开发者

What user actions trigger beforeunload in which browsers?

开发者 https://www.devze.com 2023-03-21 02:06 出处:网络
c开发者_运维知识库losing window refreshing page clicking on a link ?? It seems to be inconsistent. (I\'m shocked!) Is there a list somewhere? I\'m particularly interested in Firefox, but am curious

It seems to be inconsistent. (I'm shocked!) Is there a list somewhere? I'm particularly interested in Firefox, but am curious about others, as well. The Mozilla docs are vague:

window.onbeforeunload

An event that fires before the unload event when the page is unloaded.

window.onunload

The unload event is raised when the document is unloaded.

Gee, thanks.


window.onbeforeunload will trigger before you navigate to away from current page (from URL address, BACK button, close browser, etc.)

The event will not fire in Opera. But all the other browsers seem to respect it OK.


I have used this in the past for AJAX-intensive sites, mostly as a way to avoid having to support the BACK button.

It also works well as a confirmation dialog to prevent you from accidentally losing your work. But users might get annoyed by the confirmation. So this might not be a good enough reason to use it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号