ie localStorage 兼容问题

前端之家收集整理的这篇文章主要介绍了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).

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

猜你在找的Angularjs相关文章