Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery unload() method

jQuery unload() method

jQuery event methods jQuery event methods

Example

Display a message when leaving the page:

$(window).unload(function(){

    alert("Goodbye!");

});

Try it »


Definition and Usage

The unload() method was deprecated in jQuery version 1.8deprecated, and removed in version 3.0.

Firefox and Chrome block pop-ups, so you cannot see the effect.

The unload event occurs when the user leaves the page.

The unload event is triggered in the following situations:

The unload() method specifies what happens when the unload event occurs.

The unload() method applies only to the window object.

**Note:** The unload event behaves differently in different browsers; make sure to test this method in all browsers before using it.


Syntax

$(

selector

).unload(

function

)

Parameters Description
function Required. Specifies the function to run when the unload event is triggered.

jQuery event methods jQuery event methods