jQuery unload() Method

jQuery | unload() Method: Learn about the jQuery unload() Method with its usages, syntax, and examples.
Submitted by Pratishtha Saxena, on October 20, 2022

unload() Method

Events in jQuery are the actions that the user performs on the web page. It can be anything – related to mouse clicks, keyboard presses, etc. Using jQuery, we can control these events in the order we want and can also attach some custom functions to it if needed. That means, we can use predefined event methods for the actions and also define a function that gets fired when the event method is triggered. Overall, this makes the website more dynamic on the user's end. Let's learn about the unload() method here.

The unload event gets triggered when the page is either refreshed or has been left. When the user either goes to some other page or goes back to the previous page, then the current page gets unloaded. The unload() method is used on the windows object.

unload() Method Syntax


It takes a function as its parameter. The function is fired when the unload event is triggered on the window.

Note: Unload event has been deprecated and then further removed from version 3.0. Therefore, now we use .on() and .trigger() method to unload the URL of the page.

jQuery unload() Method Example

<!DOCTYPE html>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <h2>jQuery Event - UnLoad</h2>
    <iframe src="https://cdn.pixabay.com/photo/2016/10/26/19/00/domain-names-1772240_960_720.png" height="200px"></iframe>
  <script type="text/javascript">
        alert('Page had been Unloaded !!!');


Example 1: jQuery unload() Method

All jQuery Examples

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.