卸载前跨浏览器打开?
window.onbeforeunload()
是否在所有浏览器中触发?我需要一个至少 IE6 和 FF3.6 支持的 onbeforeunload 功能。
对于 IE,onbeforeunload()
似乎只是 IE9 支持
Does window.onbeforeunload()
fire in all browsers? I need a onbeforeunload functionality which is supported at least by IE6 and FF3.6.
For IE, onbeforeunload()
seems only to be supported by IE9
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我通过
setTimeout
函数找到了 Firefox 的解决方法,因为它的行为与其他网络浏览器不同。GitHub:https://github.com/Aelios/crossbrowser-onbeforeunload
I found a workaround for Firefox with
setTimeout
function because it does not have the same behaviour as other web browsers.GitHub: https://github.com/Aelios/crossbrowser-onbeforeunload
不,它不会在所有浏览器中触发。移动浏览器不支持它,例如 Safari、Opera Mobile 和 Opera Mobile。迷你,海豚。请参阅 是否有其他方法可以使用 onbeforeunload移动游猎?
No it does not fire in all browsers. It's not supported in mobile browsers e.g. Safari, Opera Mobile & mini, Dolphin. See Is there an alternative method to use onbeforeunload in mobile safari?
建立在 Tushar Ahirrao 解决方案的基础上,该解决方案可以跨浏览器工作并触发一次(在 Firefox、Chrome 等中工作)
将上面的模板粘贴到空文件,然后对其进行编辑
Building upon Tushar Ahirrao solution this works cross browser and triggers once (Works in Firefox, Chrome, whatever)
Paste above template to empty file then edit it
我的回忆是,IE是唯一实现
OnBeForeunLoad
的浏览器,但是一些浏览器已将其自行实施。长话短说,IE是唯一的浏览器(有限的例外),您会始终发现此事件。
It's my recollection that IE was the only browser to implement
onbeforeunload
, but some browsers have taken it upon themselves to implement it.Long story short, IE is about the only browser (with very finite exceptions) you'll find this event consistently in.
然后你可以像这样使用两者:
Then you can use both like this :