O'Reilly logo

HTML5: Your visual blueprint™ for designing rich web pages and applications by Adam McDaniel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required