当本地存储中的值发生变化时,我想在所有打开的选项卡上重新加载特定站点的页面。我怎样才能做到这一点?
最佳答案
您可以订阅storage events像这样:
window.addEventListener('storage', function(e) {
// Some storage value changed. Reload tab!
});
如链接文档中所述:
The storage event of the Window interface fires when a storage area (localStorage or sessionStorage) has been modified in the context of another document.
请注意,这仅限于可以访问同一本地存储的选项卡(受网站域限制)。
关于javascript - 重新加载 localStorage 项目更改 javascript 上的所有打开的选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56987578/