Flexible use of Html5_sessionstrong and Localstorage

Source: Internet
Author: User
Tags sessionstorage

Talk about these two properties Sessionstrong and Localstorage are HTML5 new point attributes that are used to record some data in the browser.

The difference between the two sessionstrong the stored data is temporary, and when the browser is switched off, the stored data will be erased.

Localstorage stored data is long-term, when the browser is turned off, the stored data will be saved in the browser.

The data stored in the database can be found in the resources of the browser.

With these two properties, we can do a lot of things, use it flexibly, and don't need to rely on cookies.

You must love your work, the Web, only the things you like. Only then will have the happiness, will progress.

Technical section:

To store data in a browser:

Localstorage.setitem ("heName01", "Jay Chou");

Sessionstorage.setitem ("HeName02", "JJ Lin");

Take the storage to the data and use it:

var heName01 = Localstorage.getitem ("Hename");

var heName02 = Sessionstorage.getitem ("Hename");

Console. log (heName01);//Jay Chou

Console. log (HENAME02);//JJ Lin

To erase the stored data in the browser:

Localstorage.removeitem ("heName01");

Sessionstorage.removeitem ("heName02");

Flexible use of Html5_sessionstrong and Localstorage

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.