如何解决IE11的本地存储事件触发两次或根本不在iframe? [英] How to work around IE11 localStorage events firing twice or not at all in iframes?

查看:191
本文介绍了如何解决IE11的本地存储事件触发两次或根本不在iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我猜这是一个错误,但是我还没有找到任何关于这个的讨论。



知道IE10将(反对spec)存储事件在本地(即,在触发事件的同一个全局执行上下文中),但是IE11似乎从规范( http://www.w3.org/TR/webstorage/ )当涉及到同一个域iffr:




  • 如果iframe嵌入到触发存储事件的页面中,则该事件将在该iframe中触发TWICE。

  • 如果iframe嵌入在与触发存储事件的事件不同,事件不会在该iframe内完全触发。

  • 如果事件从iframe 触发,则将在另一个页面中嵌入的任何其他iframe中的TWICE在本地和TWICE,但不是在其他页面的iframe中。



测试thi通过在两个单独的选项卡中打开以下链接: http://hansifer.com/main.html



任何人都有这个奇怪的见解?



最后测试版本: IE v11 .0.9600.16476 (update update8-13:显然是相关的更新版本,而不是IE的关于对话框中报告的版本)



链接到错误报告: https://connect.microsoft.com/IE/feedback/details/811546/ie11-localstorage-events-fire-twice-or-not -at-in-iframe



更新2015-10-26



我刚刚注意到,这似乎是在v11.0.9600.18059中修复,虽然我不知道什么时候修复掉落,因为它似乎没有被引用到任何最近的KB。



不幸的是,IE11 localStorage事件在其他方面仍然是异常的(尽管这些是与本文中提出的问题分开的牛肉):




  • IE会在触发事件的localStorage设置或删除的窗口上下文中引发localStorage事件。 localStorage事件只应在同一原点的外部窗口上下文中生成。 (更新:在EdgeHTML 13.10586中工作)


  • IE使用空字符串而不是 null <$ c当添加/删除存储项目时,$ c> e.oldValue / e.newValue (更新:EdgeHTML 13.10586中仍然存在问题)


  • IE不定式地调用localStorage事件处理程序,BEFORE或AFTER设置/删除后生效,而不是始终如一。 p>




更新2015-12-24



似乎这个错误已经转移到了Edge(已测试的EdgeHTML 13.10586)



更新版本02-02



Welp,没关系。在IE v11.63.10586.0中再次出现了这个错误(更新为08-13:显然是相关的更新版本,而不是IE的关于对话框中报告的版本)



更新版本08-13



现在看来是固定的在IE(更新版本11.0.34)中,虽然存储事件仍在起始窗口中触发,但与spec(已知的长期存在的问题如上所述)相关。



我发现此KB 已包含在 IE 2016年6月14日安全更新,尽管根据其描述,它只解决了上面的第二个项目符号。

对于Edge(经过EdgeHTML 14.14393测试),似乎还有一个问题现在已经解决了,但是有一个新的问题:存储事件不会在同一页面的同一起始帧上触发。



我单独向MS报告这里

解决方案

我可以使用 window.parent解决问题以这种方式在iframe中注册该活动:



Iframe页面

  var win = window.parent || window.opener ||窗口; 
win.addEventListener('storage',handleLocalStorageEvent,false);

函数handleLocalStorageEvent(e){
console.log('IFRAME本地存储事件',e);

var sdf = document.getElementById('sdf');
sdf.innerHTML = sdf.innerHTML +'Storage Event => ('+ e.newValue +')< br>';
}

免责声明:请注意,此解决方案修复(解决)IE11问题。以任何方式,意图或建议这适用于所有浏览器。


I'm guessing it's a bug, but I haven't been able to find any discussion about this.

It's known that IE10 will (against spec) fire storage events locally (ie, within the same global execution context from which the event was triggered), but IE11 seems to stray even further from the spec (http://www.w3.org/TR/webstorage/) when it comes to same-domain iframes:

  • if the iframe is embedded in the page that triggered the storage event, the event will fire TWICE within that iframe.
  • if the iframe is embedded in a page that is different from that which triggered the storage event, the event will not fire at all within that iframe.
  • if the event is triggered from an iframe, it will fire TWICE locally and TWICE in any other iframe embedded in the same page, but not at all in iframes of other pages.

You can test this by opening the following link in two separate tabs: http://hansifer.com/main.html

Anyone have any insight on this quirkiness?

Last tested version: IE v11.0.9600.16476 (update 2016-08-13: apparently it's the "Update Version" that's relevant, not the "Version" as reported in IE's About dialog)

Link to bug report: https://connect.microsoft.com/IE/feedback/details/811546/ie11-localstorage-events-fire-twice-or-not-at-all-in-iframes

UPDATE 2015-10-26

I just noticed that this seems to be fixed in v11.0.9600.18059, although I can't tell when the fix dropped since it doesn't seem to be referenced in any recent KB.

Unfortunately, IE11 localStorage events are still aberrant in other ways (although these are separate beefs from the issue set forth in this post):

  • IE raises localStorage events in the window context from which the localStorage set or remove that triggered the event was called. localStorage events should only be raised in foreign window contexts of the same origin. (update: working in EdgeHTML 13.10586)

  • IE uses empty string instead of null for e.oldValue/e.newValue when storage items are added/removed. (update: still a problem in EdgeHTML 13.10586)

  • IE calls localStorage event handler nondeterministically either BEFORE or AFTER set/remove takes effect instead of consistently AFTER.

UPDATE 2015-12-24

It appears this bug was carried over to Edge (tested EdgeHTML 13.10586)

UPDATE 2016-02-02

Welp, never mind. This bug is once again being observed in IE v11.63.10586.0 (update 2016-08-13: apparently it's the "Update Version" that's relevant, not the "Version" as reported in IE's About dialog)

UPDATE 2016-08-13

This now appears to be fixed in IE (Update Version 11.0.34), although storage events are still fired in the originating window, against spec (a known long-standing issue as mentioned above).

I found this KB that was included in the IE June 14, 2016 Security Update, although according to its description it only addresses the second bullet above.

As for Edge (tested EdgeHTML 14.14393), it seems also that this issue is now fixed, but there's a new problem: storage events are not firing across same-origin frames of the same page.

I reported it separately to MS here.

解决方案

I was able to work around the issue by using window.parent to register the event in the iframe in this way:

Iframe page

var win = window.parent || window.opener || window;
win.addEventListener('storage', handleLocalStorageEvent, false);

function handleLocalStorageEvent(e) {
    console.log('IFRAME local storage event', e);

    var sdf = document.getElementById('sdf');
    sdf.innerHTML = sdf.innerHTML + 'Storage Event => (' + e.newValue + ')<br>';
}

Disclaimer: Please note that this solution is meant to fix(work around) IE11 issue. By any means it is intended or suggested that this applies to all browser.

这篇关于如何解决IE11的本地存储事件触发两次或根本不在iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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