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

 

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: