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 :
- 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/
- 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