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:



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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
  • Mozilla Firefox
  • Edge
  • Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.