It is impossible to distinguish βcloseβ from βupdateβ. But you can set a cookie that contains the last time you called CloseHandler, and check when loading the module if this time is old enough to clear the information before displaying the page.
You can do this with the following utility class ( BrowserCloseDetector ). Here is an example of using it on onModuleLoad .
Test Lines :
@Override public void onModuleLoad() { if (BrowserCloseDetector.get().wasClosed()) { GWT.log("Browser was closed."); } else { GWT.log("Refreshing or returning from another page."); } }
Utility Class :
import com.google.gwt.user.client.Cookies; import com.google.gwt.user.client.Window; public class BrowserCloseDetector { private static final String COOKIE = "detector"; private static BrowserCloseDetector instance; private BrowserCloseDetector() { Window.addWindowClosingHandler(new Window.ClosingHandler() { public void onWindowClosing(Window.ClosingEvent closingEvent) { Cookies.setCookie(COOKIE, ""); } }); } public static BrowserCloseDetector get() { return (instance == null) ? instance = new BrowserCloseDetector() : instance; } public boolean wasClosed() { return Cookies.getCookie(COOKIE) == null; } }
source share