DOM:window.onunload
From MDC
Contents |
[edit] Summary
The unload event is raised when the document is unloaded.
[edit] Syntax
window.onunload = funcRef;
-
funcRefis a reference to a function.
[edit] Example
<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>
[edit] Notes
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.
[edit] Specification
DOM Level 0. Not part of any standard.