This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

unload

Overview Table

Synchronous No
Bubbles No
Target dom/Element
Cancelable No
Default action
## 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">
    alert("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>

View live example

Notes

Remarks

If you call window.open from this event, the Pop-up Blocker feature in Microsoft Internet Explorer 6 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 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. This changes affects webpages displayed in IE9 Standards mode or later document modes. The pEvtObj parameter is required for the following interfaces:

  • HTMLAnchorEvents2
  • HTMLAreaEvents2
  • HTMLButtonElementEvents2
  • HTMLControlElementEvents2
  • HTMLDocumentEvents2
  • HTMLElementEvents2
  • HTMLFormElementEvents2
  • HTMLImgEvents2
  • HTMLFrameSiteEvents2
  • HTMLInputFileElementEvents2
  • HTMLInputImageEvents2
  • HTMLInputTextElementEvents2
  • HTMLLabelEvents2
  • HTMLLinkElementEvents2
  • HTMLMapEvents2
  • HTMLMarqueeElementEvents2
  • HTMLObjectElementEvents2
  • HTMLOptionButtonElementEvents2
  • HTMLScriptEvents2
  • HTMLSelectElementEvents2
  • HTMLStyleElementEvents2
  • HTMLTableEvents2
  • HTMLTextContainerEvents2
  • HTMLWindowEvents2

Standards information

See also

Related pages

  • bodybody
  • frameSet
  • WindowWindow
  • Reference
  • Conceptual
  • About the Pop-up Blocker

Attributions