``` --- ## Definition and Usage "> ``` --- ## Definition and Usage " />
Easy Tutorial
❮ Prop Win Innerheight Innerwidth Jsref Exec Regexp ❯

onunload Event

Event Object

Example

JavaScript code to execute when the user leaves the document:

<body onunload="myFunction()">

Definition and Usage

The onunload event occurs when the user leaves the page.

onunload happens when the user navigates away from the page (by clicking a link, submitting a form, closing the browser window, etc.).

Note: The onunload event also triggers the page load event (along with the onload event).

Syntax

In HTML:

In JavaScript:

Parameter Description
SomeJavaScriptCode Required. The JavaScript to execute when the event occurs.

Browser Support

Event
onunload Yes Yes Yes Yes Yes

Note: Due to varying browser settings, this event may not work as expected.


HTML Tags That Support onunload:


❮ Prop Win Innerheight Innerwidth Jsref Exec Regexp ❯