简体   繁体   English

Internet Explorer Iframe递归window.onblur

[英]Internet Explorer Iframe recursive window.onblur

I have a funny problem that I need to solve. 我有一个有趣的问题需要解决。 In short the Internet Explorer uses the window.onblur event to focus an element in an iFrame. 简而言之,Internet Explorer使用window.onblur事件将iFrame中的元素聚焦。 Because of that it's a recursion and you cannot click anything outside of the iFrame. 因此,这是递归操作,您无法单击iFrame之外的任何内容。 Problem occurs in IE9, IE10, IE11 (not IE8 and below). IE9,IE10,IE11(不是IE8及以下版本)中出现问题。

Test it here: Try it (in IE) 在这里测试: 尝试(在IE中)

Download it here: Download it 在这里下载下载

My real question is: Is there a way to overwrite the window.onblur event inside the iFrame from outside the iFrame? 我真正的问题是:是否有办法从iFrame外部覆盖iFrame中的window.onblur事件? Is this a Bug and should I report this somewhere to Microsoft? 这是一个Bug,我应该向Microsoft举报吗?

Update 更新

Thanks for your help @Jonathan Sampson, this works as can be seen here: 感谢@Jonathan Sampson的帮助,此方法可以在此处看到:

See working example - you must wait until IFrame is fully loaded to be able to overwrite it 请参见工作示例 -您必须等到IFrame完全加载后才能覆盖它

I work on the Internet Explorer team and will gladly look into this for you. 我在Internet Explorer团队中工作,很高兴为您研究这个问题。 To answer your question about overwriting the onblur handler in the iframe, this is possible if the two documents share a common domain. 要回答有关覆盖iframe中的onblur处理程序的问题,如果两个文档共享一个公共域, 可以这样做。 In your example, this is the case. 在您的示例中,就是这种情况。

document.querySelector( "iframe" ).contentWindow.onblur = null;

Alternatively, you may only want to bind to the highest window using window.top . 另外,您可能只想使用window.top绑定到最高的窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM