HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML onunload Event Attribute

HTML Event Attributes HTML Event Attributes

Example

Execute a JavaScript when a user unloads the document:

<body onunload="goodbye()">

Try it yourself »

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The onunload event attribute is supported in all major browsers.


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).


Differences Between HTML 4.01 and HTML5

None.


Syntax

<element onunload="script">

Attribute Values

Value Description
script The script to be run on onunload


HTML Event Attributes HTML Event Attributes

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE