Used to hold key-value pairs of data, which are stored as attributes on the storage instance object
You can use Storage1.length to determine the number of key-value pairs, but cannot determine the size of the data, Storage1.remainingspace can get the remaining space size can only save data as a string, Non-string data is converted to string and stored1, SessionstorageStore data in a service session, erase the data when the browser is closed, even if the browser crashes (Firefox and WebView can, ie not)Sessionstorage.setitem ("name", "Nicholas"); It is recommended to use this methodSessionstorage.book = "Professional JavaScript";when writing data, IE is asynchronous, so when the data is large, it will feel faster, because it does not synchronously write data to the hard disk for (var i=0, len = sessionstorage.length; i < Len; i++) {//traverse content
var key = Sessionstorage.key (i); You can get the key name at the specified location var value = Sessionstorage.getitem (key); Alert (key + "=" + value);
} 2. Globalstorage object (Firefox2 implemented)to save data and some access restrictions between sessions, you need to add a domain name://save Valueglobalstorage["wrox.com"].name = "Nicholas"; So write the domain name even if the subdomain is also available, if it is www.wrox.com to restrict the sub-domain name is not available//get valuevar name = globalstorage["wrox.com"].name;Access data is subject to protocol, port, domain name and other restrictions, such as a data is stored in the case of HTTPS, then in the case of HTTP is unable to obtain the data If you are afraid of error, use:globalstorage[location.host].name = "Nicholas"; This will keep the protocol, port, domain name consistent
var book = Globalstorage[location.host].getitem ("book"); globalstorage data is saved until it is deleted, or the user is cleared of the browser cache 3, Localstorage object (that is, this later supersedes Globalstorage object, in the revised HTML5 document)this does not have to set the domain name those, because has been encapsulated, only the domain name, protocol, port consistent to obtain data, sub-domain name is not possible. for browsers that support only globalstorage:function Getlocalstorage () {
if (typeof localstorage = = "Object") { return localstorage; } else if (typeof globalstorage = = "Object") { return globalstorage[location.host]; } else { throw new Error ("Local storage Not available.");
}
}var storage = getlocalstorage (); when storage is manipulated, the storage event is triggered in document:Document.addeventlistener ("Storage", function () {alert ("Storage changed for" + Event.domain);}, False) use:Localstorage.setitem ("username", "John");alert ("username =" + localstorage.getitem ("username")); Different browser desktop or mobile phone to storage size limit is different: beyond may cause data overwrite or flash back Test Address: http://dev-test.nemikor.com/web-storage/support-test/
Web Storage offline Storage