html tutorial - onunload Attribute in HTML - html5 - html code - html form




  • The onunload attribute is used to execute a script when a page has unloaded.
  • The onunload happens when the user navigates away from the page (by clicking on a link, submitting a form, closing the browser window, etc.)
  • The onunload attribute is a section of the Event Attributes.

Syntax for onunload attribute in HTML:

<body onunload="script">

Applies to:

Elements Attribute
<body> onunload

Attribute values:

Value Description
Script The script can run on onunload.

Sample coding for onunload attribute in HTML:

<!DOCTYPE html>
<html>
    <body onload="Wikitechy()">
        <h1><Wikitechy!></h1>
        <script>
            function Wikitechy() {
                alert("Wikitechy Page is loaded");
            }
        </script>
    </body>
</html>

Code Explanation for onunload attribute:

onunload Attribute Code Explanation

  1. <body> tag encloses all the contents of an HTML document.
  2. The onunload attribute executes when an associated element has unloaded.

Browser Support for onunload attribute in HTML:

Yes Yes Yes Yes Yes

Tips and Notes:

  • If we reload a page, we will also trigger the onunload event and the onload event.

Related Searches to onunload attribute in html

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×