I am using GWT and in my application, I want to clear session history and forcefully logout user on the closing browser. But on click of refresh, the user should be logged in. I have written the following code for the same.
Window.addCloseHandler(new CloseHandler<Window>() {
@Override
public void onClose(CloseEvent<Window> event) {
logoutRPC();
}
});
Window.addWindowClosingHandler(new Window.ClosingHandler() {
public void onWindowClosing(Window.ClosingEvent closingEvent) {
logoutRPC();
}
});
But from both of the above, I am not able to achieve the functionality as refresh calls GWT.closeHandler().
How can I distinguish between both events?
It is not possible to distinguish a refresh from a close of the browser window on the client side.
Essentially your GWT application is running in the scope of the browser window. If it gets refreshed, the instance of your application gets removed, the browser loads the url and then creates a fresh instance.
You can see this when you debug and your GWT applications onModuleLoad() function gets called again on a new instance of your application class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With