Parse the new features in HTML5: Local Storage and html5localstorage

Source: Internet
Author: User
Tags sqlite manager

Parse the new features in HTML5: Local Storage and html5localstorage

Html5 local storage stores data locally through a browser.
The basic usage is as follows:

Copy the content to the clipboard using JavaScript Code
  1. <Script type = "text/javascript">
  2. LocalStorage. firstName = "Tom ";
  3. Alert (localStorage. firstName );
  4. </Script>

In this way, the data is saved locally, but in what form is the local data saved? After tracking, we found that in Chrome, data is stored as sqlite database files.
In windows, it is saved in C: \ Documents and Settings \ User Name \ Local Settings \ Application Data \ Google \ Chrome \ User Data \ Default \ Local Storage path (where User Name refers to the current User Name;
In Mac, it is stored in the/Users/User Name/Library/Application Support/Google/Chrome/Default/Local Storage path (where User Name refers to the current User Name ).
Although the suffix is. localstorege, it is actually a database file of sqlite. You can open it with sqlite and see the data in it. (You can use the SQLite Manager additional component of firefox to open it)
The steps for installing components are similar to those for installing firebug. Select the menu tool --> attachment component, open the attachment component settings page, search for the keyword "SQLite Manager", install the "SQLite Manager" plug-in, and restart firefox, you can see the "SQLite Manager" additional component in the tool, as shown in:
View the saved local data file

Below are several common localStorage methods:

1. Add localStorage

Copy XML/HTML Code to clipboard
  1. LocalStorage. setItem ("key", "value"); // store a value "value" with the name of "key"

2. Obtain localStorage

Copy XML/HTML Code to clipboard
  1. LocalStorage. getItem ("key"); // obtain the value named "key"

3. Delete localStorage

Copy XML/HTML Code to clipboard
  1. LocalStorage. removeItem ("key"); // delete information named "key"

4. Clear localStorage

Copy XML/HTML Code to clipboard
  1. LocalStorage. clear (); // clear all information in localStorage

5. view the saved localStorage

You can use the console tool Resource-Local Storage in chrome to view

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.