A site dedicated to all the cool new stuff in the HTML5 spec.

HTML5 Powered with Connectivity / Realtime, CSS3 / Styling, Device Access, Graphics, 3D & Effects, Multimedia, Performance & Integration, Semantics, and Offline & Storage


Demo

Feb 2, 2011
@ 4:00 pm
sydlawrence
Permalink

1 note

HTML5’s localStorage API

HTML5 introduces a cookie alternative. The reason for the alternative is that the data is not sent with every request. This make it easier for websites to store large data on the user’s computer.

Examples for this include uses such as storing large files offline, or storing large amounts of information, such as email archive.

The data is stored as key / value pairs. It is easily integrated due to the key / value nature.

To set some data you just need to use the following code:

window.localStorage['key'] = value;

To retreive the data you just use the localStorage array in the same manner:

return window.localStorage['key'];

To view a demo click here

Click here to view some sample code

Things to bear in mind

For obvious reasons, localStorage is domain specific, so you cannot access localStorage values from another domain.

Sites that use localStorage now

Mobile version of google mail

The official specification

http://dev.w3.org/html5/webstorage/#the-localstorage-attribute

  1. js-html5 posted this