Description
The .unload event occurs when a specified element (and sub elements) have been unloaded.
This event works with any element with an URL (like image, script, frame, iframe).
Depending on the browser, the load event may not trigger if the image is cached (Firefox and IE).
Note: There is also a jQuery Ajax method called load. Which one is called, depends on the parameter.
v1.0
This method has the form:
.unload(handler(eventObject))
Parameter | Description |
---|---|
handler(eventObject) | (required) Specifies a function to execute when the event is triggered |
Return Value
This form returns a jQuery object.
v1.4.3
This method has the alternate form:
.unload([eventData],handler(eventObject))
Parameter | Description |
---|---|
eventData | (optional) Specifies additional data to pass along to the function |
handler(eventObject) | (required) Specifies a function to execute each time the event is triggered |
Return Value
This form returns a jQuery object.
Examples
To display an alert when a page is unloaded:
$(window).unload(function () {
alert("Bye now!");
});