Close this window or press F5 to reload the page.
Note: Due to different browser settings, this event may not always work as expected
Example:
HTML
<!DOCTYPE html>
<html>
<body onunload="myFunction()">
<h1>Welcome to my Home Page</h1>
<p>Close this window or press F5 to reload the page.</p>
<p><strong>Note:</strong> Due to different browser settings, this event may not always work as expected.</p>
<script>
function myFunction() {
alert("Thank you for visiting W3Schools!");
}
</script>
</body>
</html>
Example of HTML onunload Event Attribute | Window Event Attributes |
Definition and Usage of HTML onunload Event Attribute | Window Event Attributes |
Browser Support of HTML onunload Event Attribute | Window Event Attributes |
Syntax of HTML onunload Event Attribute | Window Event Attributes |
Attribute Values of HTML onunload Event Attribute | Window Event Attributes |
How to execute a JavaScript when a user unloads the document | Window Event Attributes |
HTML onafterprint Event Attribute | Window Event Attributes |
HTML onbeforeprint Event Attribute | Window Event Attributes |
HTML onbeforeunload Event Attribute | Window Event Attributes |
HTML onerror Event Attribute | Window Event Attributes |
HTML onhashchange Event Attribute | Window Event Attributes |
HTML onload Event Attribute | Window Event Attributes |
HTML onoffline Event Attribute | Window Event Attributes |
HTML ononline Event Attribute | Window Event Attributes |
HTML onpageshow Event Attribute | Window Event Attributes |
HTML onresize Event Attribute | Window Event Attributes |
HTML onunload Event Attribute | Window Event Attributes |
Type: | html |
Category: | Web Tutorial |
Sub Category: | Window Event Attributes |
Uploaded by: | Admin |