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.

Are you a Git user? Let me help you make project management with Git simple. Checkout Gitpilot.

Follow me on Twitter: @jprichardson

-JP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.