-
Storage.setItem()Study/JavaScript 2020. 5. 16. 11:57
The setItem() method of the Storage interface, when passed a key name and value, will add that key to the given Storage object, or update that key's value if it already exists.
Syntax
storage.setItem(keyName, keyValue);
Parameters
keyNameA DOMString containing the name of the key you want to create/update.keyValueA DOMString containing the value you want to give the key you are creating/updating.
Return value
Exceptions
setItem() may throw an exception if the storage is full. Particularly, in Mobile Safari (since iOS 5) it always throws when the user enters private mode. (Safari sets the quota to 0 bytes in private mode, unlike other browsers, which allow storage in private mode using separate data containers.) Hence developers should make sure to always catch possible exceptions from setItem().
function populateStorage() { localStorage.setItem('bgcolor', 'red'); localStorage.setItem('font', 'Helvetica'); localStorage.setItem('image', 'myCat.png'); }
'Study > JavaScript' 카테고리의 다른 글
이미지 파일이 커서 뚝뚝 끊겨서 출력되는 걸 막기위한 트릭 (0) 2020.05.16 API (0) 2020.05.16 The onFulfilled and onRejected Functions (0) 2020.05.15 Consuming Promises (0) 2020.05.15 The Node setTimeout() Function (0) 2020.05.15