Original: http://www.cnblogs.com/xumingxiang/archive/2012/03/25/2416386.html
HTML5 Development Learning (2): Local storage localstorage, Sessionstorage, Globalstorage Posted on 2012-03-25 11:23 Uncle Xiang Read (2) Comments ( 0) Edit Favorites
HTML5 provides four new ways to store data on the client, namely Localstorage, Sessionstorage, Globalstorage, and Web Sql Database. This article first introduces the previous three, these three are relatively simple, understanding and operation are relatively easy, the next section focuses on Web SQL Database:
One, Localstorage:
Localstorage data storage with no time limit, data is still available after the next day, the second week, or the next year. In other words, localstorage is never expired unless the data is actively deleted. Data can span multiple windows, ignoring the current session and being collectively accessed and used. A bit like the global variable application in the ASPNET application.
Two, Sessionstorage:
As the name implies, it is like the session in ASPNET. For a session of data storage, any page stored information in the window of the same site can access its stored data. The value of each window is independent, its data will be lost due to the window's closing, the sessionstorage between different windows can not be shared.
Localstorage/sessionstorage all have the same API as
Localstorage.length get the number in storage
Localstorage. Key (n) Gets the key of the nth key-value pair in storage
Localstorage.key = value
Localstorage.setitem (key, value) added
Localstorage.getitem (key) get
Localstorage.removeitem (key) removal
Localstorage.clear () Clear
As you can see from the API above, they are actually key/value pairs, the dictionary, or JSON. Since they can be viewed as JSON, they can be manipulated in the following ways:
such as: Localstorage.name= "Xu Mingxiang";//Add
localstorage["name"]= "Xu Mingxiang"; Add to
alert (localstorage.name);//Get
Alert (localstorage["name"]);//Get
Three, Globalstorage:
After the browser is closed, the information stored with Globalstorage can still be preserved, and as with Sessionstorage, the information stored on any page in the domain can be shared by all pages. Currently only FF is supported, and only globalstorage storage under the current domain is supported.
Basic usage:
globalstorage[' developer.mozilla.org ']--all sub-domains under developer.mozilla.org can be read and written by this storage object.
globalstorage[' mozilla.org ']--all the pages under the mozilla.org domain can be read and written by this storage object.
globalstorage[' org ']--all pages under the. org domain name can be read and written by this storage object.
globalstorage[']--any page under any domain name can be read and written by this storage object.
Method Properties:
SetItem (key, value)--Sets or resets the key value.
GetItem (key)--Gets the key value.
RemoveItem (key)--Deletes the key value.
Set key value: window.globalstorage["planabc.net"].key = value;
Gets the key value: value = window.globalstorage["Planabc.net"].key;
Four, Web Sql DataBase
For more information, see Next: http://www.cnblogs.com/xumingxiang/archive/2012/03/25/2416418.html
Original address: http://www.cnblogs.com/xumingxiang/archive/2012/03/25/2416386.html
Author: Xu Mingxiang Source: Http://www.cnblogs.com/xumingxiang Copyright: This article copyright belongs to the author and blog Park are reproduced: Welcome to reprint, in order to save the author's passion, please "reprint" according to the requirements, thank you request: without the author's consent, must retain this paragraph statement; The original link must be given in the article, otherwise the legal liability will be