jQuery unload() Method
jQuery unload() event occurs when the user perform any page away action such as close window, page reload, forward/back buttons etc.
Syntax
This syntax represent to attach a function on unload event
$(selector).unload(function);
Parameter | Type | Description |
---|---|---|
function | Function | Optional. Specifies the function to execute when the unload is occurs |
Examples
This example represent the unload event
<!DOCTYPE html>
<html>
<head>
<title>jQuery unload() method</title>
<script src="jquery-latest.min.js"></script>
<script>
$(document).ready(function(){
$(window).unload(function(){
$("div").text("unload event triggered.");
});
});
</script>
</head>
<body>
<img src="../../images/img_nat.png" width="207" height="137" />
<div>Image loaded successfully.</div>
</body>
</html>