Saludos, creo que tu solucion queda asi:
<html>
<head>
<title>onload test</title>
<script type="text/javascript">
window.onunload = unloadPage;
function unloadPage()
{
alert("unload event detected!");
}
</script>
</head>
<body>
<p>The load event fires when the document has finished loading!</p>
</body>
</html>
Te recimiendo que te des una vuelta por :
https://developer.mozilla.org/en/DOM
O agregalo a favoritos, a mi me ha servido mucho, Suerte.