Easy Tutorial
❮ Tag Embed Av Event Canplaythrough ❯

HTML onunload Event Attribute

HTML Event Attributes

Example

Execute JavaScript when a user closes a page:


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

Attribute Values

Value Description
script Specifies the script to run when the onunload event is triggered.

❮ Tag Embed Av Event Canplaythrough ❯