Window.CloseListener() on refresh

Hi everyone,

I have a question regarding the Window.CloseListener().

In the mainwindow of my application, I attached a closelistener to it. Because my Vaadin application connects to a java service, I want to be able to detect when the user closes the browser or a browsertab. The closelistener does that perfectly for me.

But I noticed when the user hits the refresh button of the browser, this listener is also called.

Is it possible to detect the difference between a close and a refresh?

This would help me a lot.


Unfortunately no. The browser doesn’t inform us whether the user is navigating to some other page or to the same page again. The only message that it gives “the user is leaving the page”.

Using some sort of timer you might be able to sort this. So when the close listener is called, start the timer, and if the user doesn’t come back in a short time, close the service connection.

Thanks Jouni,

I will give it a try.

Keep up the good work :wink:

If you have given it a try could you please post here your experience / result? Thanks in advance.


a possible solution is found