English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML tag大全

HTML onunload event attribute

The unload event is triggered after the page is closed.

HTML Event Attributes

Online Example

Execute JavaScript when the document is uninstalled:

<!DOCTYPE html>
<html>
<meta charset="utf-8"> 
<title>Basic Tutorial(\3codebox.com)</title>
<head>
<script>
function say_goodbye()
{
    alert(\"Thank you for visiting the basic tutorial(\3codebox.com)\.\);
}
</script>
</head>
<body onunload="say_goodbye()">
<h1>Welcome to my homepage</h1>
<p>Closing the window or pressing F5 Refresh the page.</p>
</body>
</html>
Test and see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the onunload event attribute

Definition and Usage

The onunload attribute is triggered after the page (or browser window) is unloaded.

onunload occurs when the user navigates away from the page (by clicking a link, submitting a form, closing the browser window, etc.).
Note: If the page is reloaded, the onunload event (and onload event) will also be triggered.

HTML 4.01 and HTML5The differences between

No difference.

Syntax

<element onunload="script">

Attribute Value

ValueDescription
scriptSpecifies the script to be executed when the onunload event is triggered.
HTML Event Attributes