STORE DATA USING THE WEB STORAGE API

The Web Storage API is designed to store simple stringed values in two ways — long term to disk using localStorage and short term to the current browsing session using sessionStorage. You can use the Web Storage API to mirror or replace cookies as it has an inherently higher level of security and privacy features and is much easier to set and retrieve in JavaScript than cookies are.

There are several different ways to store data in the Web Storage API. The recommended way is by using the setItem() method on the intended storage interface:

localStorage.setItem(key, string);
 sessionStorage.setItem(key, string);

Because the storage interface emulates an associative array, the following code can be used instead, ...

Get HTML5: Your visual blueprint™ for designing rich web pages and applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.