--- title: window.onunload slug: Web/API/WindowEventHandlers/onunload translation_of: Web/API/WindowEventHandlers/onunload original_slug: Web/API/GlobalEventHandlers/onunload ---
{{ ApiRef() }}
The unload event is raised when the document is unloaded.
window.onunload = funcRef;
funcRef
is a reference to a function.<html> <head> <title>onunload test</title> <script type="text/javascript"> window.onunload = unloadPage; function unloadPage() { alert("unload event detected!"); } </script> </head> <body> <p>Reload a new page into the browser<br /> to fire the unload event for this page.</p> <p>You can also use the back or forward buttons<br /> to load a new page and fire this event.</p> </body> </html>
Note that 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.
{{ DOM0() }}
{{ languages( {"zh-cn": "zh-cn/DOM/window.onunload" } ) }}