When a user leaves the GWT app, I would like to open a confirm dialog and offer them the choice to stay, i.e. Confirm("are you sure you want to leave this page", "yes", "no").
I know how to build the dialbox. :)
The question is, how to I catch the event of a user leaving the page and how to I cancel it?
Daniel
Call the method below in the
onModuleLoad()
.You have to create a CloseHandler and register it on the Window:
Window.addWindowClosingHandler(handler)
EDIT: Fixed method name. See aem comment and answer.
Call Window.addWindowClosingHandler, and pass it a callback that calls setMessage on the Window.ClosingEvent, like so:
(I've put in links to the GWT 2.0 docs; change the 2.0 to 1.6 in those URLs to see the GWT 1.6/1.7 docs.)
Note that doing it this way, you don't have to/don't get to create the dialog box yourself.