Reputation: 21
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.
Upvotes: 0
Views: 577
Reputation: 1739
If you really have to do this, take a look at onbeforeunload
, but its implementation is inconsistent across browsers: IIRC, opera doesn't implement it.
Upvotes: 0
Reputation: 6726
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.
Upvotes: 1