Adding a Close Event When the User Closes the Browser in GWT

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.

If you made it this far, you should follow me on Twitter.

-JP

Want to test-drive Bitcoin without any risk? Check out my bitcoin wallet Coinbolt. It includes test coins for free.

comments powered by Disqus