jQuery unload()
0 1551
- This jQuery function is worked when the unload event occurs or it binds an event handler with the element when an unload event occurs.
- An unload event happens when the user navigates away from the page or a specific HTML DOM element is unloaded to the page.
- An unload event comes into existence when,
1 A link that leads to leaving the page clicked by the user.
2 User use either forward or backward button.
3 The current window closed by the user.
4 User reloads the page.
5 A new address is entered by the user into the address bar.
Related Topic:
jQuery hover
jQuery load
jQuery unload()
Note:
This method is specifically used for windows related actions and it may give different results with different browsers.
Syntax:
$(selector). unload(function);
Parameter description:
- function: It represents the function to run when the unloading of the specific page is done.
Example:
<html>
<head>
<title> jQuery Example </title>
<script type = "text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$(window).unload(function(){
alert("Thanks for visiting!");
});
});
</script>
</head>
<body>
<h2> jQuery unload() Method Example </h2>
<p> An alert box is open when you <a href="https://www.codingtag.com/"> click here! </a> </p>
</body>
</html>
Output:
Share:
Comments
Waiting for your comments