HTML onunload Event Attribute HTML Reference


Execute a JavaScript when a user unloads the document:

<body onunload="goodbye()">

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

1. Definition and Usage

The onunload attribute fires 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: If you reload a page, you will also trigger the unload event (and the onload event).

2. Differences Between HTML 4.01 and HTML5


3. Syntax

<element onunload="script">

4. Attribute Values

scriptThe script to be run on onunload

Relative articles