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
This is how the closing event works:
Window.addWindowClosingHandler(new Window.ClosingHandler()
{
@Override
public void onWindowClosing(ClosingEvent event)
{
event.setMessage("Are you sure?");
}
});
Then GWT gives the user a chance to say yes or no. Of course you can also add a test in there to see if they've got any unsaved data or whatever you want. Not setting the message or setting it to null doesn't do anything.