Javascript DOM StorageEvent oldValue Property

Introduction

Get the old value of the storage item that changed:

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

The oldValue property belongs to the Storage Event object.

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) {//from w w  w  .j  a va2s  .co m
  var txt = "Key: " + event.key + "<br>";
  txt += "Old Value: " + event.oldValue + "<br>";
  txt += "New 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 oldValue property returns the old value of the changed storage item.




PreviousNext

Related