Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Listen for changes from other tabs window.addEventListener("storage", (event) => { console.log(event.key); // Changed key console.log(event.oldValue); // Previous value console.log(event.newValue); // New value console.log(event.url); // URL of the tab that changed it if (event.key === "theme") { document.body.dataset.theme = event.newValue; } }); // Trigger by changing localStorage in another tab localStorage.setItem("theme", "dark");
Result
Open