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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to