HTML onunload Event Attribute

Description

The event attribute onunload allows you to set the script to fire when the user exits the document (including when you click on the link, submit the form, etc.).

Syntax

<element onunload="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html> 
  <html> 
    <head>
      <title>onunload event</title> 
    </head> 
    <body onunload="LeaveUser()"> 
<script> 
function LeaveUser() {
  alert("See you again!");  
} 
</script> 
  </body> 
</html>

Supported Tags

<body>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
??????
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
??????