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.
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 Standard The definition of 'onunload' in that specification. |
Living Standard | |
HTML 5.1 The definition of 'GlobalEventHandlers' in that specification. |
Recommendation | |
HTML5 The 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.
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.