简体   繁体   中英

window.onunload doesn't complete when closing IE

I have a web app running in ie, and when i close the application with click "X" right corner on IE, it will call(by javascript window.onunload) a struts action and delete a record in a table in database. But now I found it was incorrect sometimes. the record was not deleted sometimes when i close ie. It should be the case that struts action was not be called when record was not deleted.

More interesting is that when I open Fiddler, record was deleted correctly when close ie everytime, no fail case.

Thanks a lot.

You cannot rely on "onunload" event.

Think about it from the perspective of a web-browser: Should it wait till all open pages process "onunload" event, even if it takes 30 seconds? Probably browser reliably fires the "onunload" event to all open tabs, however it waits just very short time to complete them. Thats why you see inconsistent behavior.

如果确实需要执行此操作,请看一下onbeforeunload ,但是其实现在不同浏览器中是不一致的:IIRC,Opera并没有实现它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM