开发者

What user actions trigger beforeunload in which browsers?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜