Storage local storage, it seems a bit reminiscent of cookies, and indeed usage is similar to cookies. But storage has many advantages over cookies:
Large storage capacity; The client is not requested;
Storage is divided into Sessionstorage and localstorage.
1.sessionStorage temporary storage, the local storage disappears when the page is closed. and sessionstorage data is not shared.
2.localStorage permanently deleted, you can manually delete the data, the data is shared.
The following APIs are available under storage:
Window.sessionstorage and Window.localstorage have the following 4 methods:
SetItem (): Set data, Key\value type, type all strings can be manipulated in the form of Get properties
GetItem (): Gets the data through key to get to the corresponding value RemoveItem ():
Delete the data, delete the corresponding value by key
Clear (): deletes all stored values. Use the following:
Window.localStorage.getItem (' name ')
Storage events:
The storage event is triggered when the data is modified or deleted. However, in the Window object to change the data will not be triggered, that is, there are two and more than two windows, when there is data changes, in addition to their own window unexpectedly other window objects will trigger the storage event.
The event object has the following properties under it:
Key: The key value is modified or deleted, if clear () is called, key is null
NewValue: The newly set value, if called removestorage (), Key is null
OldValue: The value before the change is called
Storagearea: The current storage object
URL: The URL of the document that triggered the change in the script
As follows:
Window.addeventlistener (' storage ',function(EV) { /// Current page events do not touch Console.log (Ev.key); Console.log (ev.newvalue); Console.log (ev.oldvalue); Console.log (Ev.storagearea); Console.log (Ev.url); },false);
H5 Local Storage Storage