跨浏览器Onunload和Onbeforeunload? (特别是歌剧11) [英] cross-browser Onunload and Onbeforeunload ? (particularly opera 11)

查看:128
本文介绍了跨浏览器Onunload和Onbeforeunload? (特别是歌剧11)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,并且在退出网页时必须通知alert(),而表单中的资料尚未传送。



阅读这个歌剧有很多问题。 Opera 11是,因为我只需要考虑到最后版本。



再次,警报应该在刷新,关闭标签或关闭整个浏览器时显示。
将事件直接设置到< form> 元素,这将在任何导致销毁此元素的东西上启动。

解决方案

Opera尚不支持onbeforeunload。 Opera的onunload支持是不完整的 - 例如,当关闭标签页或关闭Opera时它不会触发。据我所知,虽然你可以使用onunload显示一个警告,如果用户点击链接导航离开一个未保存的表单的页面,没有办法,你可以防止导航发生时unload事件触发。 / p>

我这里做的是监听onbeforeunload事件,使它在其他浏览器中工作,等待Opera赶上。无论是在Opera 12或13或15我不知道,但当onbeforeunload实现它将工作像在其他浏览器中已经。


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.

解决方案

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.

这篇关于跨浏览器Onunload和Onbeforeunload? (特别是歌剧11)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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