Localstorage and sessionstorage usage records (recommended), sessionlocalstorage
By reading the Usage Analysis of locastorage and sessionstorage on web storage, I tried it myself and made a note here.
If a project uses storage for many times and stores a lot of data, it should be encapsulated into a function:
(This function is written by an unknown great god. If there is any violation of originality, please contact me ......)
Function setStorage (key, value) {if (! Window. localStorage) {alert ("the browser does not support localstorage"); return false;} else {var storage = window. localStorage; // write the field storage. setItem (key, value) ;}} function getStorage (key) {if (! Window. localStorage) {alert ("the browser does not support localstorage");} else {var storage = window. localStorage; var key = storage. getItem (key); // console. log (key); return key ;}}
SetStorage stores data, and the key is the specified data name. It can be set as needed, but it must be a string type. Otherwise, the browser automatically uses the value as the key name.
The first value is that the key is not specified as a string, that is, no double quotation marks are added.
Double quotation marks must also be added for string types of value values.
How can I view storage in a browser?
View the location of a newer version of chrome browser
If the same data storage function is called multiple times in a project, the data changes in real time. If you need to clear all stored data:
Localstorage. clear (); or sessionStorage. clear ();
The principle used in the project is to use the data to call the function for storing the data.
The above section describes the usage records of localstorage and sessionstorage (recommended). I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!