DHTML Events
Fires immediately before the object is unloaded.
Inline HTML |
<element onunload = "handler" ... > |
All platforms |
Event property |
object.onunload = handler |
ECMA-262 Language Specification |
Named script |
<script FOR=object EVENT=onunload> |
Internet Explorer® only |
Bubbles |
No |
Cancels |
No |
To invoke |
Cause the browser to unload the object. |
Default action |
Removes the object or document from the browser window. |
An unload event occurs when the user agent removes a document from a window or frame. This event is valid for the BODY and FRAMESET elements.
While event handlers in the Document Object Model do not receive parameters directly, the handler can query the event object for data.
Event Object Properties
type |
Retrieves the event name from the event object. |
The example shows how to use the onunload event to run script when the window object has been unloaded.
Sample Code
<script for=window event=onunload>
alert("The onunload event has just fired
for this window object.");
</script>
<script language="JavaScript">
function openSamp ( ) {
location.href="history.aspx";}
</script>
</head>
<body>
<input type=button value="Next Page"
onclick="openSamp()">
</body>
Show me
FRAMESET, IMG, window
onload, onreadyStatechange