.unload()    **DEPRECATED**S2C Home « Events « .unload()

Unload event handler.


The .unload() method is used to bind an event handler to the JavaScript unload event.

  • The unload event is passed to the window object whenever a user navigates away from a page for any of the following reasons:
    1. The user has clicked on an external link.
    2. The user has pressed the page reload button.
    3. The user has pressed the forward or back navigation buttons.
    4. The user has typed a new URL in the address bar.
    5. The user has closed the browser window.
    6. Whether the event is triggered often depends on the browser being used and can even vary in different versions of a particular browser.

This method was deprecated in jQuery 1.8.


Signature Description
.unload( [eventData], handler(eventObject) )Bind an event handler to the load JavaScript event, optionally passing an object of data.


Parameter Description Type
eventDataAn object of data to pass to the event handler.Object
handler( eventObject )A function to execute each time the event is triggered.Function


A jQuery object.

.unload( [eventData], handler(eventObject) ) Examplego to top of page Top

  • This signature is a shortcut for .bind('unload', handler).

Bind an event handler to the unload JavaScript event, optionally passing a map of data.

As soon as we navigate away from the page the unload JavaScript event occurs. In the example below we show an alert message when this happens.

$(window).unload(function() {
  alert('The Javascript unload event has been triggered.');

go to home page Homepage go to top of page Top