I am writing an application in GWT and I need to detect when a user navigates away from my application or when he closes the browser window (onUnload event) and do a logout (session invalidation and few other cleanup tasks). The logout action is performed by a servlet.
I am currently doing this by hooking into the onUnload() event and opening a new window pointed to the logout servlet.
Is there a better way to do this? Any other suggestions are welcome.