Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML onunload Event Attribute

HTML onunload Event Attribute

HTML Event Attributes HTML Event Attributes

Example

Execute JavaScript when the user closes a page:

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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 HTML Event Attributes