HTML onunload Event Attribute
Example
Execute JavaScript when the user closes a page:
Try it »
Browser support





All major browsers support the onunload event attribute
Definition and Usage
The onunload attribute is triggered when the user closes a page.
onunload is triggered when the user leaves the page (by clicking a link, submitting a form, closing the browser window, etc.).
Note: If you reload the page, the unload event will be triggered ( onload event).
Differences between HTML 4.01 and HTML5
None.
Syntax
<
element
onunload="
script
">
HTML Event Attributes