Adding a Close Event When the User Closes the Browser in GWT
August 6, 2010 Leave a comment
Often times your GWT app will queue up client side RPC events. What if the user clicks close on the browser window or tries to navigate to a new page? The solution is very simple.
Window.addWindowClosingHandler(new ClosingHandler(){
@Override public void onWindowClosing(ClosingEvent event) {
event.setMessage("If you leave, you may lose data. Continue?");
}
});
Simple as pie. If event.setMessage is called, a prompt will be displayed for you.
Are you a Git user? Let me help you make project management with Git simple. Checkout Gitpilot.
Follow me on Twitter: @jprichardson
-JP