For browsers, using Web Storage to store key values compared to storing cookies is more intuitive and more capacity, it contains two kinds: Localstorage and Sessionstorage
Sessionstorage (Temporary storage): maintains a storage area for each data source that exists during browser opening, including page reload
Localstorage (long-term storage): Same as Sessionstorage, but when the browser is closed, the data remains
1. Save data to Local
Sessionstorage.setitem (' key ', ' your Data ');
Localstorage.setitem (' key ', ' your Data ');
2. Getting data from local storage
var data1 = Json.parse (sessionstorage.getitem (' key '));
var data2 = Json.parse (localstorage.getitem (' key '));
3. Delete a saved data from the local store
Sessionstorage.removeitem (' key ');
Localstorage.removeitem (' key ');
4. Delete all saved data
Sessionstorage.clear ();
Localstorage.clear ();
5. Monitor changes to local storage
Description: Storage changes (add, update, delete) when the trigger, the same page changes will not trigger, will only listen to the same domain name other page changes Storage
Window.addeventlistener (' storage ', function (e) {
Console.log (' key ', e.key);
Console.log (' OldValue ', e.oldvalue);
Console.log (' newvalue ', e.newvalue);
Console.log (' url ', e.url);
})
6. Browser Viewing methods
1. Go to Developer tools
2. Select Application
3. Check the Local Storage and Session Storage on the left Storage
Web Local Storage (localstorage, sessionstorage)