Web Storage

 Web Storage


Web storage is a way to store data in a user's browser using the localStorage and sessionStorage APIs. This can be useful for saving user preferences, caching data, and reducing server requests.

Here's an example of how to use localStorage to store and retrieve data:



<!DOCTYPE html>

<html>

  <head>

    <title>Web Storage Example</title>

    <script>

      function saveData() {

        var name = document.getElementById("name").value;

        localStorage.setItem("username", name);

      }

      function loadData() {

        var name = localStorage.getItem("username");

        document.getElementById("display-name").innerHTML = name;

      }

    </script>

  </head>

  <body onload="loadData()">

    <h1>Welcome</h1>

    <p>Enter your name:</p>

    <input type="text" id="name">

    <button onclick="saveData()">Save</button>

    <p>Your name is: <span id="display-name"></span></p>

  </body>

</html>

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...