onunload event
Examples
Javascript code is executed when the user has not loaded the document:
<body onunload="myFunction()">
try it"
Definition and Usage
onunload event occurs when the user exits the page.
onunload event occurs when the user when leaving the page (by clicking a link, submitting a form, close the browser window, and so on.)
Note: onunload event also triggers the page load event (+ the onload event).
grammar
In HTML:
<body
onunload="SomeJavaScriptCode">
In JavaScript:
window.onunload=function(){SomeJavaScriptCode};
参数 | 描述 |
---|---|
SomeJavaScriptCode | 必需。规定该事件发生时执行的 JavaScript。 |
Browser Support
IE, Firefox, and Safari support onunload event, but Chrome or Opera do not support the event.
The following HTML tags support onunload:
<body>, <frameset>
Event objects