JavaScript authoritative guide Section 20 client memory

Source: Internet
Author: User
Tags web database sessionstorage

Client memory

Several forms of client storage:

Web Memory

Cookies

IE UserData

Offline applications

Web Database

File System API

20.1 Localstorage and Sessionstorage

20.1.1 Storage expiration and scope

The difference between Localstorage and Sessionstorage is that the storage has a different validity period and scope.

The scope of the Localstorage is limited at the document source level.

Document Source: protocol hostname port determines the same document source

Source documents can share the same localstorage, and can even change and overwrite localstorage.

The scope of Localstorage is limited by different browser vendors.

Source documents can share the same sessionstorage, the scope is limited to the form, and the form here refers to the top-level form.

<iframe> of homologous document sources can share sessionstorage.

Test whether the browser supports this feature:

<strong>function Test () {var a = Window.localstorage;if (a) {alert ("Your browser supports Localstorage");} else {Ale RT ("Your browser Dosen ' t support Localstorage");}} </strong>


20.1.2 Storage API

Manipulating storage objects and properties

<strong>localstorage.setitem ("UserName", "Michael"); Localstorage.getitem (); Localstorage.removeitem (); Localstorage.delete (); Localstorage.clear ();</strong>

20.1.3 Storage Events

local storage for HTML5. A storage event is also provided . Ability to listen for changes to key-value pairs, such as the following:

if (Window.addeventlistener) {
Window.addeventlistener ("Storage", handle_storage,false);
}else if (window.attachevent) {
Window.attachevent ("Onstorage", handle_storage);
}
function Handle_storage (e) {
if (!e) {e=window.event;}
Showstorage ();
}

20.2 Cookies

20.2.1 Cookie Expiration and scope

Not to be continued


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

JavaScript authoritative guide Section 20 client memory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.