Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (42 sloc) 2.43 KB
<?xml version="1.0"?>
<entry type="method" name="unload" return="jQuery">
<argument name="handler(eventObject)" type="Function">
<desc>A function to execute when the event is triggered.</desc>
<argument name="eventData" type="Object" optional="true">
<desc>A map of data that will be passed to the event handler.</desc>
<argument name="handler(eventObject)" type="Function">
<desc>A function to execute each time the event is triggered.</desc>
<desc>Bind an event handler to the "unload" JavaScript event.</desc>
<p>This method is a shortcut for <code>.bind('unload', handler)</code>.</p>
<p>The <code>unload</code> event is sent to the <code>window</code> element when the user navigates away from the page. This could mean one of many things. The user could have clicked on a link to leave the page, or typed in a new URL in the address bar. The forward and back buttons will trigger the event. Closing the browser window will cause the event to be triggered. Even a page reload will first create an <code>unload</code> event.</p>
<p>The exact handling of the <code>unload</code> event has varied from version to version of browsers. For example, some versions of Firefox trigger the event when a link is followed, but not when the window is closed. In practical usage, behavior should be tested on all supported browsers, and contrasted with the proprietary <code>beforeunload</code> event.</p>
<p>Any <code>unload</code> event handler should be bound to the <code>window</code> object:</p>
<pre><code>$(window).unload(function() {
alert('Handler for .unload() called.');
<p>After this code executes, the alert will be displayed whenever the browser leaves the current page.
It is not possible to cancel the <code>unload</code> event with <code>.preventDefault()</code>. This event is available so that scripts can perform cleanup when the user leaves the page.
<desc>To display an alert when a page is unloaded:</desc>
<code><![CDATA[$(window).unload( function () { alert("Bye now!"); } );]]></code>
<category slug="events/document-loading"/>
<category slug="version/1.0"/>
<category slug="version/1.4.3"/>
Jump to Line
Something went wrong with that request. Please try again.