Skip to content
Related Articles
Open in App
Not now

Related Articles

HTML | onunload Event Attribute

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 16 Aug, 2022
Improve Article
Save Article

The onunload event attribute works when the document is being unloaded i.e. it occurs when the browser has been closed. It is mostly used when the user open link and submit the form and close the browser window. 
Supported Tags: 

  • <body>

Syntax: 
 

<element onunload = "script">

Attribute Value: This attribute contains single value script which works when onunload event triggered.
Example: 
 

html




<!DOCTYPE html>
<html>
    <head>
        <title>
            HTML onunload Event Attribute
        </title>
         
        <script>
            function Geeks() {
                alert("onunload event attribute called");
            }
        </script>
    </head>
     
    <body onunload = "Geeks()">
        <h1>GeeksforGeeks</h1>
         
        <h2>onunload Event Attribute</h2>
     
    </body>
</html>                                   

Output: 
 

Note: This event may not work always as expected.
Supported Browsers: The browser supported by onunload event attribute are listed below: 
 

  • Google Chrome 1
  • Edge 12
  • Internet Explorer 4
  • Firefox 1
  • Safari 3
  • Opera 4

 

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!