Fires immediately before the object is unloaded.
![]() |
Syntax
| HTML Attribute | <element onunload = "handler(event)"> |
|---|---|
| Event Property | object.onunload = handler; |
Event information
| Synchronous | No |
|---|---|
| Bubbles | No |
| Cancelable | No |
Event handler parameters
- pEvtObj [in]
-
Type: IHTMLEventObj
Standards information
- HTML 4.01 Specification, Section 18.2.3
Remarks
If you call window.open from this event, the Pop-up Blocker feature in a Windows Store app using JavaScript prevents the pop-up window from appearing.
Removes the object or document from the browser window.
To invoke this event, do one of the following:
- Close the current window.
- Navigate to another location by entering a new address or selecting a Favorite.
- Click the Back, Forward, Refresh, or Home button.
- Click an anchor that refers the browser to another document.
- Invoke the anchor.click method.
- Invoke the document.write method.
- Invoke the document.open method.
- Invoke the document.close method.
- Invoke the window.close method.
- Invoke the window.open method, providing the possible value _self for the window name.
- Invoke the window.navigate or NavigateAndFind method.
- Invoke the location.replace method.
- Invoke the location.reload method.
- Specify a new value for the location.href property.
- Submit a form to the address specified in the ACTION attribute via the INPUT type=submit control, or invoke the form.submit method.
For security reasons, the unload event does not open modeless dialog boxes, such as those created with the alert method or the showModelessDialog method. This changes affects webpages displayed in a Windows Store app using JavaScript or later document modes.
Examples
This example shows how to use the onunload event to run script when the window object has been unloaded.
<head>
<script type="text/javascript" for="window" event="onunload">
console.log("The onunload event fired for the window object.");
</script>
<script type="text/javascript">
function fnRelocate()
{
location.href="/workshop/samples/author/dhtml/refs/onunloadEX_target.htm";
}
</script>
</head>
<body>
<input type="button" value="Go To Page 2" onclick="fnRelocate()">
</body>
See also
- body
- window
- Reference
- onload
- onbeforeunload
- Conceptual
- About the Pop-up Blocker
Send comments about this topic to Microsoft
Build date: 11/29/2012
