ie localStorage 兼容问题

原文如下:

IE 11 - Local Storage - Synchronization issues - by WalkMe

状态 : 

ID 812563 建议
Status Closed 解决方法
类型 Bug

9
打开日期 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).
建议    |    解决方法    |    Attachments 

由  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、单纯使用第一种方法不能保证在所有情况下都有效。但结合第二种方法后,会好很多

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值