localStorage property allows you to access a
Storage object for the
Document's origin; the stored data is saved across browser sessions.
localStorage is similar to
sessionStorage, except that while data stored in
localStorage has no expiration time, data stored in
sessionStorage gets cleared when the page session ends — that is, when the page is closed.
It should be noted that data stored in either
sessionStorage is specific to the protocol of the page.
myStorage = window.localStorage;
Storage object which can be used to access the current origin's local storage space.
- The request violates a policy decision, or the origin is not a valid scheme/host/port tuple (this can happen if the origin uses the
data:scheme, for example). For example, the user may have their browser configured to deny permission to persist data for the specified origin.
The syntax for reading the localStorage item is as follows:
var cat = localStorage.getItem('myCat');
The syntax for removing the localStorage item is as follows:
The syntax for removing all the localStorage items is as follows:
// clear all items localStorage.clear();
Note: Please refer to the Using the Web Storage API article for a full example.
|HTML Living Standard
The definition of 'localStorage' in that specification.
|Feature||Android webview||Chrome for Android||Edge mobile||Firefox for Android||Opera Android||iOS Safari||Samsung Internet|