The onunload
property of the WindowEventHandlers
mixin is the EventHandler
for processing unload
events. These events fire when the window is unloading its content and resources. The resource removal is processed after the unload
event occurs.
Note: Browsers equipped with pop-up blockers will ignore all Window.open()
method calls in onunload
event handler functions.
The onunload
(and the unload
event itself) are not the right features to use with sendBeacon()
. Instead for sendBeacon(),
use the visibilitychange
and pagehide
events. See discussion comments in the blog post Beacon API is broken.
Syntax
window.addEventListener("unload", function(event) { ... }); window.onunload = function(event) { ... };
Typically, it is better to use window.addEventListener()
and the unload
event, instead of onunload
.
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living StandardThe definition of 'onunload' in that specification. | Living Standard | |
HTML 5.1The definition of 'GlobalEventHandlers' in that specification. | Recommendation | |
HTML5The definition of 'GlobalEventHandlers' in that specification. | Recommendation |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
onunload
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support Yes |
IE
Full support Yes |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support Yes |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
In Firefox 1.5, using this event handler in your page prevents the browser from caching the page in the in-memory bfcache. See Using Firefox 1.5 caching for details.
WindowEventHandlers.onunload by Mozilla Contributors is licensed under CC-BY-SA 2.5.