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

onunload Event

Event Object Reference Event Object

Example

Execute a JavaScript when a user unloads the document:

<body onunload="myFunction()">

Try it yourself »

Definition and Usage

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: The onunload event is also triggered when a user reloads the page (+ the onload event).

Syntax

In HTML:

<body onunload="SomeJavaScriptCode">

In JavaScript:

window.onunload=function(){SomeJavaScriptCode};

Parameter Description
SomeJavaScriptCode Required. Specifies a JavaScript to be executed when the event occurs


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The onunload event is supported in IE, Firefox, and Safari, but not supported properly in Chrome or Opera.


onunload is Supported by the Following HTML Tags:

<body>, <frameset>


Event Object Reference Event Object

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