Https://www.cnblogs.com/yaoyuqian/p/7901052.html
There are two types of Web Storage: Sessionstorage and Localstorage (both are limited to the document source level and cannot be shared between non-homologous documents)
1.sessionstorage data placed on the server (ie not supported) is strictly used to store data in a browser session and the data will be deleted immediately after the browser is closed. Span class= "Hljs-number" >2.localstorage data on the client (low version IE (IE6, IE7) is not supported, and the query language is not supported) store data persistently across sessions localstorage and Sessionsto Rage difference: Localstorage can read/modify to the same Localstorage data as long as the same protocol, the same hostname, and the same port. Sessionstorage is a bit more stringent than localstorage, except for protocols, hostnames, and ports, and requires the same window (that is, the browser's tab). Use the same: (Take sessionstorage as an example) 1. Added: Sessionstorage.setitem (key, value); //value can be any data type 2. Get: Sessionstorage.getitem (key); 3. Delete: Sessionstorage.removeitem (key); //Delete the key value of the storage object in the keys to 4. Clear all: Sessionstorage.clear (); //clears all the key values in the storage object 5. Search (check): Sessionstorage.key ();
Localstorage.setitem ("x", 1);//stores a numeric value with the name "x" localstorage.x = 1;//Adds a key/value pair Localstorage.getitem directly to the Web storage object (" X ");//Get the value localstorage.x;//retrieve the key/value pair Localstorage.removeitem (" x ") directly from the Web storage object;//delete the" X "item. //removeitem is the only common way to delete a single name-value pair. (because IE8 does not support the delete operator) localstorage.clear ();//delete all. The only way to delete all name-value pairs in a Stored object //to store an array as a string var MyArray = new Array (' First name ', ' Last Name ', ' Email Address '); Localstorage.formdata = Json.stringify (MyArray); Retrieve the string version of the array and convert it to an available JavaScript array var myArray = Json.parse (Localstorage.formdata);
There is a more practical way to access:
/span>
var obj = {
Name: ' Doctorhou ',
Describe: ' tall, mighty, handsome '
};
Localstorage.setitem (' Test ', json.stringify (obj));
var getobj = json.parse (Localstorage.getitem (' Test '));
When the storage data changes (corresponding events): Window.onstorage
Example:
<body>
Web Storage mechanisms Localstorage and Sessionstorage