跨浏览器 Onunload 和 Onbeforeunload ? (特别是歌剧11)
我有一个表单,当表单中有数据尚未发送时,我必须在退出页面上使用alert()通知用户。
我读到歌剧在这方面有很多问题。也就是说,Opera 11,因为我只需要考虑最后一个版本。
同样,警报应该在刷新、关闭选项卡或关闭整个浏览器时显示。 最好将事件直接设置到
I have a form and I must notice user with alert() on exiting page while there are data in the form that had not been send.
I've read that opera has a lot of problems with this. Opera 11 that is, because I need take into account only last version.
So again, the alert should display on refresh, closing a tab, or closing whole browser.
It would be nice to set event directly to the <form>
element that would be launched on anything that leads to destroying this element.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Opera 尚不支持 onbeforeunload。 Opera 的 onunload 支持不完整 - 例如,当您关闭选项卡或关闭 Opera 时它不会触发。据我所知,虽然您可以使用 onunload 在用户单击链接导航离开具有未保存表单的页面时显示警告,但您无法阻止卸载事件触发时发生导航。
我在这里要做的是监听 onbeforeunload 事件,使其在其他浏览器中工作并等待 Opera 赶上。我不知道它是否会在 Opera 12、13 或 15 中出现,但是当实现 onbeforeunload 时,它会像在其他浏览器中一样工作。
Opera does not yet support onbeforeunload. Opera's onunload support is incomplete - for example, it does not fire when you close a tab, or close Opera. As far as I know, while you can use onunload to show a warning if a user clicks a link to navigate away from a page with an unsaved form, there is no way you can prevent the navigation from happening when the unload event fires.
What I would do here is to listen for the onbeforeunload event, make it work in other browsers and wait for Opera to catch up. Whether it will be in Opera 12 or 13 or 15 I don't know, but when onbeforeunload is implemented it will work like it does in other browsers already.
禁用关闭 还无法帮助您,因为 Opera 不支持 window.onbeforeunload那一刻。未来的某个版本将会支持它。目前,Opera 11 还没有实现它。
The Disable Close will not help you yet because Opera does not support window.onbeforeunload at the moment. It will be supported in some future version. For now, Opera 11 doesn't implement it.
自 Opera 15 起现在支持 onbeforeunload !
onbeforeunload is now supported since Opera 15 !
JQuery 框架只是一种压缩的 Javascript 语言,因此它完全取决于您使用的浏览器,这里没有魔法。
The JQuery framework is only a condensed Javascript language so it depends entirely on the browser you use, no magic here.