WindowEventHandlers.onunload
The onunload
property of the WindowEventHandlers
mixin is the event handler 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.
Warning: 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 |
---|
HTML Standard (HTML) # handler-window-onunload |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
onunload |
1 |
12 |
9 |
≤6 |
≤12.1 |
≤4 |
≤37 |
18 |
9 |
≤12.1 |
≤3 |
1.0 |
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.
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onunload