HBCMS更多的中文手册参考:

onunload Event

DHTML文档教程

Fires immediately before the object is unloaded.

dhtml语法

Inline HTML<ELEMENT onunload = "handler" ... > All platforms
Event propertyobject.onunload = handlerJScript only
object.onunload = GetRef("handler")Visual Basic Scripting Edition (VBScript) 5.0 or later only
Named script <SCRIPT FOR = object EVENT = onunload> Internet Explorer only

Event Information

BubblesNo
CancelsNo
To invoke
  • Close the current browser window.
  • Navigate to another location by entering a new address or selecting a Favorite.
  • Click the Back, Forward, Refresh, or Home button.
  • Click on an anchor that refers the browser to another web page.
  • invoke the anchor?a href="../methods/click.html">click method.
  • invoke the document?a href="../methods/write.html">write method.
  • invoke the document?a href="../methods/open_1.html">open method.
  • invoke the document?a href="../methods/close_1.html">close method.
  • invoke the window?a href="../methods/close_0.html">close method.
  • invoke the window?a href="../methods/open_0.html">open method, providing the possible value _self for the window name.
  • invoke the window?a href="../methods/navigate.html">navigate or navigateandfind method.
  • invoke the location?a href="../methods/replace.html">replace method.
  • invoke the location?a href="../methods/reload.html">reload method.
  • specify a new value for the location?a href="../properties/href_3.html">href property.
  • submit a form to the address specified in the action attribute via the INPUT type=submit control, or invoke the submit method.
Default action Removes the object or document from the browser window.

Event Object Properties

Although event handlers in the DHTML Object Model do not receive parameters directly, a handler can query an event object for data.

available properties

altKey Sets or retrieves a value that indicates the state of the ALT key.
altLeft Sets or retrieves a value that indicates the state of the left ALT key.
ctrlLeft Sets or retrieves the state of the left CTRL key.
shiftLeft Retrieves the state of the left SHIFT key.
type Sets or retrieves the event name from the event object.

DHTML代码范例

This example shows how to use the onunload event to run script when the window object has been unloaded.

<HEAD>
<SCRIPT FOR=window EVENT=onunload>
alert("The onunload event fired for the window object.");
</SCRIPT>
<SCRIPT>
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()">
<IMG ID=imgTest SRC="../common/prop_rw.gif">
</BODY>
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

是否符合公共标准

This event is defined in HTML 4.0 Non-Microsoft link.

Applies To

BODY, FRAMESET, window

更多语法参考

onload, onbeforeunload