您的位置:首页 > 其它

ie localStorage 兼容问题

2016-07-01 11:43 225 查看
参考方案来自https://connect.microsoft.com/IE/feedback/details/812563/ie-11-local-storage-synchronization-issues
原文如下:


IE 11 - Local Storage - Synchronization issues - by WalkMe


状态 : 

ID812563建议12
StatusClosed解决方法4
类型Bug9
打开日期2013/12/31 0:24:14
访问限制Public


描述

While working with two IE 11 windows, in each an iframe of the same domain, values stored in one iframe (using local storage) are not synchronized to the other iframe.
This in contradiction to the specification (other browser act correctly).


详细信息

建议 (12)   |   解决方法 (4)   |   Attachments (5)

由 AlexandreJobin 在 2016/2/16 7:48 发送
I confirm that the @Vageesh Dwivedi solution works for me. Each time i have to write new data to the localStorage, i also create a dummy item and remove it right away and my tabs are
now synced.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
由 Kiyokura 在 2015/4/27 17:29 发送
I found a workaround (IE11 on Win8.1).

Add the following code, update of other tabs is synchronized well:

----

window.addEventListener("storage", function (e) {

// Dummy

}, false);

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

由 Vageesh Dwivedi 在 2015/3/4 6:14 发送
I also faced a similar issue.

Scenario : window 1 is domain.com and has an iframe of domainx.com, window 2 is domainx.com. I wanted localstorage based communication between window 1's iframe and window 2.

The listener and polling technique didn't work and indexedDB workaround was too big for this small problem. After a few hacks, the localStorage keys were synced when i did -

localStorage.setItem('dummy', 'dummyvalue');

localStorage.removeItem('dummy');

in iframe on window 1.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

由 WalkMe 在 2014/2/5 4:03 发送
As a workaround we used indexed DB instead of local storage.

The indexed DB synchronizes well, but it is async compared to the local storage which is sync.

To overcome this difference we used web workers and gave them the job of writing the data, so it was done almost in parallel.

Still prefer an official solution :)

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

我的方法:
我的解决方案取自上文的前两种方法,即使用增加和移除虚假的item更新localStorage,同时定义使用window.addEventListener("storage",function(e){ // Dummy   },false); 
1、当然可以单独使用第二种方法,测试有效
2、单纯使用第一种方法不能保证在所有情况下都有效。但结合第二种方法后,会好很多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: