dojo/_base/unload

Summary

This module contains the document and window unload detection API. This module is deprecated. Use on(window, "unload", func) and on(window, "beforeunload", func) instead.

See the dojo/_base/unload reference documentation for more information.

Methods

addOnUnload(obj,functionName)

Defined by dojo/_base/unload

Registers a function to be triggered when the page unloads. Deprecated, use on(window, "beforeunload", lang.hitch(obj, functionName)) instead.

The first time that addOnUnload is called Dojo will register a page listener to trigger your unload handler with.

In a browser environment, the functions will be triggered during the window.onbeforeunload event. Be careful of doing too much work in an unload handler. onbeforeunload can be triggered if a link to download a file is clicked, or if the link is a javascript: link. In these cases, the onbeforeunload event fires, but the document is not actually destroyed. So be careful about doing destructive operations in a dojo.addOnUnload callback.

Further note that calling dojo.addOnUnload will prevent browsers from using a "fast back" cache to make page loading via back button instantaneous.

Parameter Type Description
obj Object? | Function
Optional
functionName String | Function
Optional

Examples

Example 1

var afunc = function() {console.log("global function");};
require(["dojo/_base/unload"], function(unload) {
    var foo = {bar: function(){ console.log("bar unloading...");}, 
               data: "mydata"};
    unload.addOnUnload(afunc);
    unload.addOnUnload(foo, "bar");
    unload.addOnUnload(foo, function(){console.log("", this.data);});
});

addOnWindowUnload(obj,functionName)

Defined by dojo/_base/unload

Registers a function to be triggered when window.onunload fires. Deprecated, use on(window, "unload", lang.hitch(obj, functionName)) instead.

The first time that addOnWindowUnload is called Dojo will register a page listener to trigger your unload handler with. Note that registering these handlers may destroy "fastback" page caching in browsers that support it. Be careful trying to modify the DOM or access JavaScript properties during this phase of page unloading: they may not always be available. Consider addOnUnload() if you need to modify the DOM or do heavy JavaScript work since it fires at the equivalent of the page's "onbeforeunload" event.

Parameter Type Description
obj Object | Function
Optional
functionName String | Function
Optional

Examples

Example 1

var afunc = function() {console.log("global function");};
require(["dojo/_base/unload"], function(unload) {
    var foo = {bar: function(){ console.log("bar unloading...");}, 
               data: "mydata"};
    unload.addOnWindowUnload(afunc);
    unload.addOnWindowUnload(foo, "bar");
    unload.addOnWindowUnload(foo, function(){console.log("", this.data);});
});

© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/_base/unload.html