win8.1中的localStorage IE11不同步 [英] localStorage in win8.1 IE11 does not synchronize

查看:141
本文介绍了win8.1中的localStorage IE11不同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有两页/ read和/ write。页面/ write每秒用当前时间更新localStorage:

We have two pages "/read" and "/write". Page "/write" each second updates localStorage with current time:

setInterval(function(){
    var time = (new Date()).getTime();
    localStorage.setItem("time", time);
    console.log("set", time);
},1000);

页面/ read读取相同的存储空间:

Page "/read" reads same storage:

setInterval(function(){
    var time = localStorage.getItem("time");
    console.log("get", time);
},1000);

有人会认为/ read页面应该显示由另一个写入localStorage的相同值页。但是在Win8.1的IE11中,这已经破了。页面/ read从存储中读取一些旧值,并在其上进一步显示相同的值(就像它使用缓存进行本地存储一样)。有什么想法?

One would think that "/read" page should show the same values which are written to localStorage by another page. But in IE11 on Win8.1 this is broken. Page "/read" reads some old value from storage, and further on it will show you the same value (as if it uses cache for local storage). Any ideas?

P.S。这两个页面都位于同一个域中(实例 - 阅读 write

P.S. Both pages are on the same domain (live example - read write)

推荐答案

我在Win 10上找到了解决此问题的方法。如果你处理window.onstorage事件在您的代码中,localStorage将刷新所有打开的选项卡。
这对我来说很简单:

I've found a workaround for this issue on Win 10. If you handle the window.onstorage event in your code then localStorage will refresh for all open tabs. Something as simple as this worked for me:

window.onstorage = function(e){
    //Leave this empty
    //or add code to handle
    //the event
};

我没有彻底测试过这段代码,所以请在任何制作应用中使用此方法之前这样做。

I haven't tested this code thoroughly, so please do so before using this method in any production apps.

希望这会有所帮助!

这篇关于win8.1中的localStorage IE11不同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆