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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.