Html5 local storage, html5localstorage

Source: Internet
Author: User
Tags sessionstorage

Html5 local storage, html5localstorage

HTML5 provides two new methods to store data on the client:

  • LocalStorage-data storage with no time limit
  • SessionStorage-data storage for a session

Open review elements (such as Google F12) in a browser and view the data in Resources.

LocalStorage provides several methods: 1. Storage: localStorage. setItem (key, value); or localStorage. key = "value"; if the key exists, update value 2. Obtain: localStorage. getItem (key); or localStorage. getItem ("key"); if the key does not exist, null is returned. 3. Delete: localStorage. once the removeItem (key) is deleted, all data corresponding to the key will be deleted. 4. Clear all data: localStorage. clear () In some cases, it is too difficult to delete removeItem one by one. You can use clear. The result of the execution is that all the data stored in the localStorage object will be cleared. 5. traverse the key stored in the localStorage. total length data, for example, localStorage. length. key (index) to obtain the key, for example, var k Ey = localStorage. key (index); 6. JSON format data is stored. stringify (data) converts an object into a JSON data string and returns the converted JSON string. parse (data) parses data into an object, and returns the parsed object SessionStorage. Note: Data stored in localStorage cannot be shared across browsers. A browser can only read data from its own browsers, with a storage space of 5 MB.

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.