Access localstorage event across tabs - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window localStorage

Description

Access localstorage event across tabs

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Tab1</title> 
   </head> 
   <body> 
      <button id="add" onclick="localStorage.setItem('tab','changed')">Add</button> 
      <button id="clear" onclick="localStorage.clear()">Clear</button> 
      <script type="text/javascript">
    function onStorageEvent() {//  w  w  w .  j a v  a2s. c om
      console.log("storage event: " + localStorage.getItem("tab"));
    }
    window.addEventListener('storage', onStorageEvent);
  
      </script>  
   </body>
</html>

Related Tutorials