unload() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:unload

Description

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

The unload event occurs when the user navigates away from the page.

Syntax

Parameter Require Description
function Required. function to run when the unload event is triggered

The following code shows how to Alert a message when navigating away from the page:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(window).unload(function(){/*from   w  w  w  .  j a  v a 2  s  .  c o  m*/
        console.log("Goodbye!");
    });
});
</script>
</head>
<body>

<p>click <a href="http://java2s.com">this link</a> to trigger unload event.</p>

</body>
</html>

Related Tutorials