Chapter 2

Simple Persistence with the Web Storage API

Load and store persistent string data with the Web Storage API, using local storage or session storage. Data is stored as key-value pairs.


Recipe 2.1
Checking for Web Storage Support

Check if local storage is available for use in the current browser.

Recipe 2.2
Persisting String Data

Use local storage to remember the color selected with a color picker.

Recipe 2.3
Persisting Simple Objects

Stringify an object and persist the resulting JSON in local storage.

Recipe 2.4
Persisting Complex Objects

Use JSON replacer and reviver functions to customize object serialization.

Recipe 2.5
Listening for Storage Changes

Listen for local storage changes from other tabs on the same page.

Recipe 2.6
Finding All Known Keys

Inspect the local storage area to generate an array of known keys.

Recipe 2.7
Removing Data

Remove data from local storage.

Web Browser API Cookbook
Joe Attardi