HTML5 Web Storage uses HTML5 to store users ' browsing data locally. Earlier, local storage was using cookies. But Web storage needs to be more secure and fast. This data is not saved on the server, but it is used only for user requests for Web site data. It can also store large amounts of data without compromising the performance of the site. Data is present in key/value pairs, and the Web page's data is only allowed to be used for that page.
localstorage and sessionstorage
The two objects that the client stores data are:
Localstorage-Data storage with no time limit sessionstorage-data storage for a session
Before using Web Storage, you should check whether your browser supports localstorage and sessionstorage:
if (typeof (Storage)!== "undefined") { //YES! Support Localstorage Sessionstorage Object!} else { //sorry! Web Storage is not supported. }
Localstorage Object
The data stored by the Localstorage object has no time limit. Data is still available after the second, second, or next year.
Localstorage.sitename= "old cat teacher";
document.getElementById ("Result"). Innerhtml= "website name:" + localstorage.sitename;
Instance parsing:
Create a Localstorage key/value pair using key= "sitename" and value= "old cat teacher". Retrieves the value of the key value "sitename" and then inserts the data into the element id= "result"
Sessionstorage Object
The Sessionstorage method stores data for a session. When the user closes the browser window, the data is deleted.
How to create and access a sessionstorage:
if (sessionstorage.clickcount) {sessionstorage.clickcount=number (Sessionstorage.clickcount) +1;} else{ sessionstorage.clickcount=1;} document.getElementById ("Result"). Innerhtml= "In this session you have clicked the button" + Sessionstorage.clickcount + "Times";
Whether it is localstorage, or sessionstorage, can use the same API, commonly used are the following (in the case of Localstorage):
Save data: Localstorage.setitem (Key,value);
Read data: Localstorage.getitem (key);
Delete individual data: Localstorage.removeitem (key);
Delete all data: Localstorage.clear ();
Get the Key:localStorage.key (index) of an index;
Here's a simple JSON
Json:json's full name is "JavaScript Object Notation", which means that JavaScript objects represent methods, which is a lightweight data interchange format based on text, independent and language.
I remember the struggle of their own, is he let the present himself, enjoy the good, to the still struggle you, hope and June mutual encouragement.
My Enlightenment--HTML5 The fourth chapter local storage