Storage Events and Limits
React to changes and respect quota limits.
Reacting to Storage Changes
The storage event lets one tab react when another tab changes localStorage. It enables simple cross-tab synchronization.
Listening for storage
Add a listener on window. It fires in OTHER tabs of the same origin whenever localStorage changes, not in the tab that made the change.
window.addEventListener("storage", (e) => {
console.log("Key changed:", e.key);
});All lessons in this course
- Storing and Reading Data
- localStorage vs sessionStorage
- Storing Objects with JSON
- Storage Events and Limits