Project

General

Profile

WApplication::unload() not being called

Added by Nathan Ridge over 11 years ago

I am trying to do some cleanup when a user navigates away from my application, and I understand WApplication::unload() is an appropriate place to do it. However, I am finding that unload() doesn't always get called when the user navigates away. For example, with Firefox it seems to be called when the user presses Back, but not when they close the tab. With Chrome, it seems to be called when they close the tab, but not when they press Back. Is this expected?

I know I could put the cleanup in the WApplication destructor, but that doesn't get called until the session times out, and I need to do some cleanup right away.


Replies (3)

RE: WApplication::unload() not being called - Added by Koen Deforche over 11 years ago

Hey,

There is no guarantee that the unload() will be called, it depends on an internal race condition in the browser (whether it still allows some JavaScript to be executed, and a new XMLHttpRequest being sent).

If you want to do a cleanup more quickly then there is no other choice but reducing the session timeout parameter (at the expense of more keep-alive requests).

Regards,

koen

RE: WApplication::unload() not being called - Added by Nathan Ridge over 11 years ago

I see. So this is a browser issue, rather than a Wt issue? What is the mechanism by which WApplication::unload() is called?

RE: WApplication::unload() not being called - Added by Koen Deforche over 11 years ago

A XMLHttpRequest is being sent by the browser in the window onunload() event.

    (1-3/3)