Session
- Session: The entire process from opening a page of the WEB browser to closing the browser is called “a session between the browser and the WEB server”.
window.sessionStorage
- Array object: session-level data storage that can be shared by the pages of this session and disappear when the browser closes.
sessionStorage[key]=val; // Save a data
sessionStorage.setitem(key,val); // Save a data
var val = sessionStorage['key']; // Read a data
var val= sessionStorage.getitem('key'); // Read a data
sessionStorage.removeltem('key'); // Delete data
sessionStorage.length; // Data length
sessionStorage.key(i); // Get the i-th key
Copy the code
Window.localstorage Stores objects locally (across sessions and stores)
- The user data is stored in the managed external storage (disk) of the browser, which can be used by the pages of this session and subsequent sessions. Even if the browser is closed, it doesn’t go away — forever
localStorage[key]=val; // Save a data
localStorage.setitem(key,val); // Save a data
var val = localStorage['key']; // Read a data
var val= localStorage.getitem('key'); // Read a data
localStorage.removeltem('key'); // Delete data
localStorage.length; // Number of data
localStorage.key(i); // Get the i-th key
Copy the code
- ** *localStorage () : window.onstorage () : window.onstorage () : window.onstorage () : window.onstorage ();