localStorage.js

var name = localStorage.username; // Query a stored value. name = localStorage["username"]; // Array notation equivalent if (!name) { name = prompt("What is your name?"); // Ask the user a question. localStorage.username = name; // Store the user's response. } // Iterate through all stored name/value pairs for(var name in localStorage) { // Iterate all stored names var value = localStorage[name]; // Look up the value of each one }
Storage lifetime and scope are explained in more detail below. First, however, let’s look at some examples. The following code uses localStorage, but it would also work with sessionStorage:

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.