HTML | DOM Storage Event

The Storage Event in HTML DOM is used to make change in the storage area in the context of another document. When there is modification in the storage area of the window, a storage event is sent to that window. 

Syntax:

window.addEventListener("storage", script)

Example: 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM storage Event
    </title>
</head>
 
<body>
     
    <h1>w3wiki</h1>
     
    <h2>HTML DOM storage Event</h2>
     
    <button onclick = "myBeginner()">
        Click here!
    </button>
     
    <p id = "cont"></p>
     
    <!-- script of DOM storage event -->
    <script>
        window.addEventListener("storage", myBeginner1);
         
        function myBeginner1(event) {
            document.getElementById("cont").innerHTML
                    = "A Computer Science Portal";
        }
         
        function myBeginner() {
            var x = window.open("", "win",
                    "width = 100, height = 100");
                     
            x.localStorage.setItem("mytime", Date.now());
            x.close();
        }
    </script>
</body>
 
</html>                               


Output: Before Click on the button:

  

After Click on the button:

  

Supported Browsers: The browser supported by DOM Storage Event property are listed below:

  • Google Chrome 1 and above
  • Mozilla Firefox 45 and above
  • Edge 15 and above
  • Safari 4 and above
  • Opera 15 and above
  • Internet Explorer 9 and above