Get the new value of the storage item that changed.
The storage event is only triggered when a window other than itself makes the changes.
The newValue property belongs to the Storage Event object.
<!DOCTYPE html> <html> <body> <button onclick="changeValue()">Change a Storage Item</button> <p id="demo"></p> <script> window.addEventListener("storage", myFunction); function myFunction(event) {/*from w w w. jav a 2 s.com*/ var txt = "Key: " + event.key + "<br>"; txt += "Value: " + event.newValue; document.getElementById("demo").innerHTML = txt; } function changeValue() { var x = window.open("", "myWindow", "width=200,height=100"); x.localStorage.setItem("mytime", Date.now()); x.close(); } </script> </body> </html>
The newValue property returns the new value of the changed storage item.