Execute a JavaScript when a user unloads the document:
The onunload event occurs once a page has unloaded (or the browser window has been closed).
onunload occurs when the user navigates away from the page (by clicking on a link, submitting a form, closing the browser window, etc.)
Note: you will also trigger the unload event when a user relaods the page (and the onload event).
In HTML:
In JavaScript:
| Parameter | Description |
|---|---|
| SomeJavaScriptCode | Required. Specifies a JavaScript to be executed when the event occurs |
![]()
The onunload event is supported in IE, Firefox, and Safari, but not supported properly in Chrome or Opera.
Event Object
Your message has been sent to W3Schools.