A storage event is an event that gets triggered when changes are made to the localStorage or sessionStorage objects. This event allows different tabs or windows to communicate with each other when the stored data is modified.
storage event triggered?storage event is fired when:
localStorage or sessionStorage.You can listen to the storage event using the window.addEventListener method:
localStorage:
localStorage:
storage event properties| Property | Description |
|---|---|
key | The key that was changed (null if clear() is called). |
newValue | The new value of the key (null if the key was removed). |
oldValue | The old value of the key (null if the key was added). |
storageArea | Specifies whether localStorage or sessionStorage was modified. |
url | The URL of the document where the change occurred. |
If the value of 'theme' is changed from 'dark' to 'light', the console will show:
storage event only works across different browser tabs or windows.sessionStorage changes do not trigger the event between different tabs because sessionStorage is unique to each tab.