DOM Window unload event, is it reliable?

≯℡__Kan透↙ 提交于 2019-12-18 03:54:57

问题


Can I rely on the window unload event to be triggered when a user closes a tab/window/browser?

Edit:

Found a list of what triggers the unload event in IE. http://msdn.microsoft.com/en-us/library/ms536973%28VS.85%29.aspx

I would like to know in which edge cases the unload event won't be triggered.


回答1:


You will likely want to use the "onbeforeunload" event too, it provides more control than the "onunload" event.

That said, be aware that: Opera doesn’t fire the unload event when the browser refreshes the page, or uses the back/forward buttons to browse off of the page. What’s worse, Opera never fires the onbeforeunload event. Thus if you are supporting Opera - be aware of these issues.




回答2:


Not in all circumstances no. The browser could crash etc. keeping the event from firing. The user could also use add-ons like Grease Monkey to prevent the event from firing also.



来源:https://stackoverflow.com/questions/1594548/dom-window-unload-event-is-it-reliable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!