Google chrome onbeforeunload iframe 的错误行为
假设我有两页。其中一个包含另一个作为 iframe 的内部。如果您在父页面上订阅了 onbeforeunload 事件,则当 iframe 处于焦点状态时关闭选项卡时,该事件不会触发。我认为这是一个错误,如下所示: Google Chrome 问题
但我提到过,例如 google文档处理这种情况。谁能给我一个解决方案吗? 重要提示,我无法实际访问 iframe 内容,因为它是第三方 html 编辑器 (WYSIWYG)。
Let say I have two pages. One of them contains another one inside as iframe. If you subscribe to onbeforeunload event on the parent page, then this event doesn't triggers if you close tab when iframe is in focus. I suppose it is a bug as written here:
Google Chrome issues
But I mentioned that, for example, google docs handle this situation. Can anyone give me a solution?
Important note that I have no actual access to the iframe content as it is a third party html editor (WYSIWYG).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这是一个老问题,但只是为了帮助通过搜索来到这里的人:
错误是 现在已修复。
从 chrome 10 开始,这个问题应该得到解决。
这里有一个相关错误。
因此,简而言之,如果您仍然无法在框架上触发“
onbeforeunload
”,则可能是由于通过 JavaScript 更改了内容,例如document.open
document .write
document.close
等。I know it is an old question but just to help people who are coming here through Search :
The bug is fixed by now here.
Since chrome 10, the issue should be fixed.
There is a related bug though here.
So, in short if you still not able to fire "
onbeforeunload
" on frames, it could be due to change in the content through JavaScript likedocument.open
document.write
document.close
etc.下面的代码将在所有浏览器上运行,
尝试一次......
the below code will work across all the browsers
try this once ...
您还可以尝试将 iframe 的 url 更改为“about:blank”,例如:
它强制 chrome“干净地”关闭 iframe 中包含的窗口。
只是提一下:如果您只想关闭 iframe 而不是父窗口,则必须给 chrome 足够的时间来执行附加到“onbeforeunload”的处理程序。
You may also try to change the iframe's url to "about:blank", e.g.:
It forces chrome to "cleanly" close the window containted within the iframe.
Just to mention: if you want to close only your iframe but not the parent window, you have to give chrome enough time to execute the handler you've attached to 'onbeforeunload'.