Learn html, css, javascript online and how to make a webpage design

How to user Window localStorage Property?

Friday 1st of January 2021 11:27:49 PMjavascriptlocalStorage

Create a localStorage name/value pair with name="website" and value="htmlcssdownload.com", then retrieve the value of "website" and insert it into the element with id="result":

<!DOCTYPE html>
    <title>How to use window localStorage property? - HtmlcssDownload.com</title>
<div id="result"></div>
<script type="text/javascript">
    // Store
    localStorage.setItem("website", "htmlcssdownload.com");
    // Retrieve
    document.getElementById("result").innerHTML = localStorage.getItem("website");


Definition and Usage

The localStorage and sessionStorage properties allow to save key/value pairs in a web browser.

The localStorage object stores data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

The localStorage property is read-only.

We are Recommending you: