[HTML5] Data storage

Source: Internet
Author: User

HTML5 using JavaScript to store and access data

Data storage :

Browser support : Mainstream full support ("IE 8.0", "Chrome 4.0", "Firefox 4.0", "Safari 4.0", "Android 3.0", "IOS 5.0");

Maximum size : 5M;

form :

Localstorage: Local storage with no time limit for stored data:

<script type= "Text/javascript" > localstorage.lastname= "Smith"; document.write (localstorage.lastname); </script>

Sessionstorage: Server storage, when the user closes the browser window, the data is deleted:

<script type= "Text/javascript" > sessionstorage.lastname= "Smith"; document.write (sessionstorage.lastname); </script>

Store Common APIs (only strings can be manipulated):

SetItem (key, value) Adds a key/value pair for the Web storage object for later use. The value can be any data type: string, numeric, array, and so on.
Json.stringify To store an array as a string
Variable test and adjustment Use the variable as a way to use it. (localstorage.name = ' content ';)
GetItem (Key) Retrieves a value for the key that was originally used to store it.
RemoveItem (Key) Remove key/value represented by key
Clear () Clears all key/value pairs.
Key (N) Retrieves the value of Key[n].

Json.stringify How to use:

var New Array (' First name ', ' Last Name ', ' Email Address '= json.stringify (MyArray);

The final tip :

    1. Internet Explorer 8+, Opera 10.5+, Firefox 3.5+, Safari 4+, and Chrome all include a local JSON object, and for a lower version of the browser, you can download a json2.js file:/http www.json.org/
    2. HTML5 brings new storage, but for Internet security, it is still as fragile and insecure as the way cookies and sessions are stored.

[HTML5] Data storage

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.