English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The unload event is triggered after the page is closed.
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 ‹/›
IEFirefoxOperaChromeSafari
All major browsers support the onunload event attribute
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.
No difference.
<element onunload="script">
Value | Description |
---|---|
script | Specifies the script to be executed when the onunload event is triggered. |