Advertisement
728x90
The StorageEvent is an event that fires when a storage area has been changed in the context of another document. Whereas onstorage property is an EventHandler for processing storage events.
The syntax would be as below
javascript
1window.onstorage = functionRef;Let's take the example usage of onstorage event handler which logs the storage key and it's values
javascript
1window.onstorage = function (e) {
2
3console.log(
4 "The " +
5 e.key +
6 " key has been changed from " +
7 e.oldValue +
8 " to " +
9 e.newValue +
10 "."
11);
12};Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 48
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
46of476