[Dojo-interest] How to hook addOnUnload?
James Burke
jburke at dojotoolkit.org
Tue Jan 30 09:57:10 MST 2007
On 1/30/07, troyf <troyf at adbeast.com> wrote:
>
>
> Hello,
>
> Has anybody hooked the window.onbeforeunload event? Dojo provides
> addOnUnload but I can't seem to figure out how to cancel that. From the
> reading that I have done it looks like onBeforeUnload should be called, but
> dojo doesn't expose that (at least that I can find).
>
> I have a piece of code that fires when a user leaves a page containing a
> form. It checks the form to see if there is any unsaved data. If there is,
> a message is displayed prompting the user to save or continue leaving the
> page. If the user chooses to save then dojo.io.bind is called. However,
> once the user ends up on the new page (a listview of records) the data saved
> in the preceding page is not displayed, unless they refresh.
>
> I *think* that it is because I am using dojos addOnUnload. Instead I should
> be using the window.onBeforeUnload event to trap for the page change,
> execute my save procedure and then let the page finally redirect.
>
> Are there any issues with using window.onBeforeUnload? Are there any
> cross-browser issues? And finally, is it possible to use dojo.event.connect
> with a window event?
>
> Thanks as always for any assistance,
>
> Troy
IIRC, Safari didn't call my unload handler if the user closed the
browser via the browser chrome's close button. However, beforeunload
was called, so I could do cleanup/verification in that event callback.
So I ended up relying on beforeunload more to do final verification
steps.
You should be able to use dojo.event.connect.
James
More information about the Dojo-interest
mailing list