title: Best way to detect browser closing/navigation to other page and do logout
body: <p>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. </p>
  
  <p>I am currently doing this by hooking into the onUnload() event and opening a new window pointed to the logout servlet. </p>
  
  <p>Is there a better way to do this? Any other suggestions are welcome.</p>