JavaScript window.localStorage Property

You are Here:

JavaScript window.localStorage Property

The window.localStorage property allows you to access and save data (key/value pairs) in a web browser.

Note: The key points for window.localStorage property as follows

  • Unlike sessionStorage, the data stored in localStorage has no expiration time, i.e., the data will NOT be deleted when the browser is closed, and will be available the next day, week, or year.
  • The keys and values are always strings.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var len = window.localStorage.length; var txt = "The local storage length is " +len; document.write(txt); </script> </body> </html>

Syntax

window.localStorage

Save and Access Local Storage

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <script> var x = document.getElementById("point"); // Adding one data to local storage if(typeof(Storage) !== "undefined") { localStorage.setItem("website", "wikimass.com"); x.innerHTML = localStorage.getItem("website"); } else{ x.innerHTML = "Sorry, your browser does not support Web Storage"; } // check local storage length var len = window.localStorage.length; var txt = "The local storage length is " +len; document.write(txt); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author