Web Local storage sessionstorage and Localstorage

Source: Internet
Author: User
Tags sessionstorage

1, sessionstorage temporary storage

Maintains a storage area for each data source, which exists during browser opening, including page reload.

2, Localstorage long-term storage

Same as Sessionstorage, but data will persist after the browser is closed

Save data to Local

var userinfo={      name:"Zhang San", age      :$,      likes:"song"} Sessionstorage.setitem ("key", Json.stringify (UserInfo)); Localstorage.setitem (

Get data from local storage

var data1=json.parse (Sessionsrorage.getitem ("key")); var data2=json.parse (Localstorage.getitem ("key"));

Delete a saved data from the local store

Sessionsrorage.removeitem ("key"); Localstorage.removeitem ("key");

Delete all saved data

Sessionsrorage.clear (); Localstorage.clear ();

Monitor changes to local storage

Storage changes (add, update, delete) when the trigger, the same page changes will not trigger, will only listen to the same domain name other page changes Storage

function (e) {        console.log (' key ', E.key);        Console.log (' OldValue ', e.oldvalue);        Console.log (' newvalue ', e.newvalue);        Console.log (' url ', e.url);})

Web Local storage sessionstorage 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.