The unload event is raised when the window is unloading its content and resources. The resources removal is processed after the unload event occurs.

Syntax

window.onunload = funcRef;
  • funcRef is a reference to a function.

Notes

Using this event handler in your page prevents Firefox 1.5 from caching the page in the in-memory bfcache. See Using Firefox 1.5 caching for details.

Browsers equipped with pop-up window blockers will ignore all window.open() method calls in onunload event handler functions.

You can and should handle this event through window.addEventListener() and the unload event. More documentation is available there.

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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

Document Tags and Contributors

Last updated by: sideshowbarker,