Catching Window.onUnload event

1,344 views
Skip to first unread message

buz...@gmail.com

unread,
Sep 3, 2008, 5:13:01 AM9/3/08
to Google Web Toolkit
Hello,

Is there a way in GWT to catch Window.onUnload event.

I need that to detect when user navigates away from the page, but does
not close the browser.
I have written a native implementation, but are there any plans to add
Window.addUnloadListener() functionality?
Or am I missing something?

My implementation looked like this () :

public abstract class MeasuringEntryPoint implements EntryPoint {

private static final List onunloadListneners = new ArrayList();

public MeasuringEntryPoint() {
attachOnUnloadListener();

addUnloadListener(new
MeasuringEntryPoint.WindowUnloadListener() {
public void onWindowUnloaded() {
detachOnUnloadListener();
Collection measurements =
MeasurementStorage.retrieveMeasurements();
MeasurementDeliveryGateway.deliver(measurements);
}
});
}

public static void addUnloadListener(WindowUnloadListener
listener) {
onunloadListneners.add(listener);
}

public static void onUnload() {
for (Iterator iterator = onunloadListneners.iterator();
iterator.hasNext();) {
WindowUnloadListener listener = (WindowUnloadListener)
iterator.next();
listener.onWindowUnloaded();
}
}

private native void attachOnUnloadListener() /*-{
$wnd.onunload = function() {
@com.mycoolapp.gwt.client.MeasuringEntryPoint::onUnload()
();
}
}-*/;

private native void detachOnUnloadListener() /*-{
$wnd.onunload = null
}-*/;

}

Thanks,
Dmitry

Thomas Broyer

unread,
Sep 3, 2008, 9:28:07 AM9/3/08
to Google Web Toolkit


On 3 sep, 11:13, "buz...@gmail.com" <buz...@gmail.com> wrote:
> Hello,
>
> Is there a way in GWT to catch Window.onUnload event.

use a WindowCloseListener.

> I need that to detect when user navigates away from the page, but does
> not close the browser.

This is not possible in JavaScript, there's only an 'unload' event, no
'close' event or similar.

> I have written a native implementation, but are there any plans to add
> Window.addUnloadListener() functionality?
> Or am I missing something?

Window.addWindowCloseListener *is* relying on beforeunload and unload
events.

jagadish panigrahi

unread,
Apr 21, 2015, 2:44:09 PM4/21/15
to google-we...@googlegroups.com, buz...@gmail.com, Google-We...@googlegroups.com
Hi Dimitri,
Did you find any solution in GWT for above mentioned problem that would invoke an event when user navigates away from the screen without closing it
Reply all
Reply to author
Forward
0 new messages