jQuery unload()

The jQuery unload() method is used to unload a specific element. It attaches an event handler to unload event. The unload event is sent to the window element when the user navigates away from the page. It was deprecated in jQuery 1.8 version of jQuery library.

Syntax
$(selector).unload(function)

The unload() method specifies what happens when a unload event occurs.The unload() method should only be used on the window object.The unload event might work differently in different browsers.

Ways to trigger unload event

An unload event is triggered if you:
       I.            Click on a link which leads to leave the page.
     II.            Use the forward or back button.
  III.            Type a new URL in the address bar.
  IV.            Close the browser window.

Example -1

<!DOCTYPE html> 
<html> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
<script> 
$(document).ready(function(){ 
    $(window).unload(function(){ 
        alert("Goodbye!"); 
    }); 
}); 
</script> 
</head> 
<body> 
<p>When you click <a href="http://www.dotnettpoint.blogspot.com/">this link</a>, or close the window, 
 unload event will be triggered.</p> 
</body> 
</html>