I stuck this in a .js file...
window.onbeforeunload = alert('onbeforeunload');
But it fires when the page is loaded, not when it is unloaded.
Does anyone know why?
You have to wrap it... try this instead:
window.onbeforeunload = function(){alert('onbeforeunload')};