Prevent window change/close

Hello everybody,

I have the following problem to solve:

Whenever an user accesses a specific part from our application, he should not be able to leave that page without clicking a confirm button.

The question is: is there any way to prevent that the user closes the window or goes to another page outside the application?

I tried to use the Navigator.addViewChangeListener, but it only prevents the user to go to other views inside the application.

Any Idea?

Thank you very much for any help!

Vaadin has no built-in mechanism to prevent closing the browser window, but you should be able to have confirmation for that with window.onbeforeunload event, as described
for example here
. Just inject it with JavaScript.execute() or otherwise and it might work (I haven’t tried it).

Thank you very much for your fast reply, Marko!