Vaadin - execute Javascript on windowclose is not working

Hi

In my application when I close the browser window using the ‘X’ icon in the title bar. I want to display alert message / confirmation dialog to user. Since in Vaadin there is no default option for confirmation box on window close , I am planning to include javascript to show alert message/confirmation box, but when I try executeJavaScript() method inside the window close listener it is not getting executed and the browser window closes without showing the alert message. Can somebody help me how to achieve this in Vaadin.

Thanks.

If I remember correctly, window close() listener Vaadin 6 uses is asynchronous and thus further interaction is not possible any more as the window is already closed.

To show alert and possibly block the window close, you should add a blocking window close listener in javascript (possibly with executeJavaScipt).

Hi Joonas,

Can you provide the sample implementation for blocking window close listener in javascript.

Hi ,
Can you assist me with implementing the blocking window close listener in javascript.
Thanks

Take a look at onbeforeunload event | beforeunload event JavaScript

Did not try myself, but i would try to add unbeforeunload event usign window.executeJavascript. On the event handler show a dialog and cancel the event if you want to block closing the window.