RETRIEVE DATA FROM THE WEB STORAGE API

Retrieving data from the Web Storage API is just as easy as storing it. The only thing you need to be careful of is that the context of what you access will be retrieved as a string, so if you are expecting a number or object type, some post-retrieval conversion is required.

All Web Storage events occur relative to the user’s current domain. This means that if a user visits your website at www.mycompany.com/path/to/storage.html, anything stored there can be accessible only from other JavaScript code running within www.mycompany.com.

There are different ways to retrieve data stored in the Web Storage API:

string = localStorage.getItem(key);
string = sessionStorage.getItem(key);

This will return null

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.