JS In addition to the cookie store, but also what storage mode?

Source: Internet
Author: User
Tags browser cache sessionstorage

IE provides a store that can persist user data, called UserData, from IE5.0 to support. Up to 128K per data, up to 1M per domain. This persisted data is stored in the cache and will persist if the cache is not cleaned up.

<div style= "Behavior:url (#default #userdata)" id= "box" ></div>

addevent (window, ' Load ', function () {

var box = document.getElementById (' box ');

Box.setattribute (' name ', encodeURIComponent (' Li Tinghui '));

Box.save (' BookInfo ');

Box.removeattribute (' name ');//Delete userdate

Box.save (' BookInfo ');

Box.load (' BookInfo ');

Alert (decodeuricomponent) (Box.getattribute (' name '));

});

PS: This data file is also stored in the cookie directory, as long as the cookie can be erased. If you specify an expiration date, it is automatically deleted after expiration, and is persisted if not specified.

Web Storage

In a newer version of the browser, JavaScript provides sessionstorage and globalstorage. In HTML5, Localstorage is provided to replace the globalstorage. The minimum version of the browser is: ie8+, firefox3.5+, Chrome 4+ and opera10.5+.

PS: Because these three browser version requirements are high, we simply understand in Firefox, interested in the keyword search query.

Storing and retrieving by methods

Sessionstorage.setitem (' name ', ' Li Tinghui ');

Alert (Sessionstorage.getitem (' name '));

Storing and retrieving by attributes

Sessionstorage.book = ' Li Tinghui ';

alert (Sessionstorage.book);

Delete Storage

Sessionstorage.removeitem (' name ');

PS: Because Localstorage replaces Globalstorage, the latest version of Firefox, opera and Chrome is not supported.

Storing and retrieving by methods

Localstorage.setitem (' name ', ' Li Tinghui ');

Alert (Localstorage.getitem (' name '));

Storing and retrieving by attributes

Localstorage.book = ' Li Tinghui ';

alert (Localstorage.book);

Delete Storage

Localstorage.removeitem (' name ');

PS: These three objects are permanently saved in the cache, and can only be invalidated by manual deletion or by cleaning the browser cache. There are also some restrictions on capacity, mainly looking at browser differences, firefox3+, ie8+, Opera for 5m,,chrome and Safari for 2.5M.

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.