Javascript DOM StorageEvent storageArea Property

Introduction

The Storage Event is triggered when there is a change in the window's storage area.

The storage event is only triggered when a window other than itself makes the changes.

The storageArea property belongs to the Storage Event object.

It returns the Storage object of the item that was changed.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="changeValue()">Change a Storage Item</button>
<p id="demo"></p>
<script>
window.addEventListener("storage", myFunction);
function myFunction(event) {// w w w  .  java 2 s .com
  x = event.storageArea;
  document.getElementById("demo").innerHTML = x;
}
function changeValue() {
  var x = window.open("", "myWindow", "width=200,height=100");
  x.localStorage.setItem("mytime", Date.now());
  x.close();
}
</script>
</body>
</html>

The storageArea property returns the Storage Object of the changed storage item.




PreviousNext

Related