This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2017.
The storage event of the Window interface fires when another document that shares the same storage area (either localStorage or sessionStorage) as the current window updates that storage area. The event is not fired on the window that made the change.
localStorage, the event is fired in all other browsing contexts that are in the same origin as the initiating document. This includes other tabs with the same origin.sessionStorage, the event is fired in all other browsing contexts that are in the same origin and the same top-level browsing context as the initiating document. This only includes embedded iframes, if any, in the same tab, and not other tabs.This event is not cancelable and does not bubble.
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("storage", (event) => { })
onstorage = (event) => { }
A StorageEvent. Inherits from Event.
key Read only
Returns a string with the key for the storage item that was changed. The key attribute is null when the change is caused by the storage clear() method.
newValue Read only
Returns a string with the new value of the storage item that was changed. This value is null when the change has been invoked by storage clear() method, or the storage item has been removed from the storage.
oldValue Read only
Returns a string with the original value of the storage item that was changed. This value is null when the storage item has been newly added and therefore doesn't have any previous value.
storageArea Read only
Returns a Storage object that represents the storage object that was affected.
url Read only
Returns string with the URL of the document whose storage changed.
In addition to the Window interface, the event handler property onstorage is also available on the following targets:
Log the sampleList item to the console when the storage event fires:
window.addEventListener("storage", () => {
// When local storage changes, dump the list to
// the console.
console.log(JSON.parse(window.localStorage.getItem("sampleList")));
});
The same action can be achieved using the onstorage event handler property:
window.onstorage = () => {
// When local storage changes, dump the list to
// the console.
console.log(JSON.parse(window.localStorage.getItem("sampleList")));
};
| Specification |
|---|
| HTML> # event-storage> |
| HTML> # handler-window-onstorage> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
storage_event |
1 | 15 | 45 | 15 | 4 | 18 | 45 | 14 | 4 | 1.0 | 4.4 | 4 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event