Mel said:
<body>
<button onclick="
window.onunload = function()
{
alert('Leaving...');
}
">Click this</button>
<a href="
http://www.yahoo.com">Then click this</a>
</body>
Works in Firefox 1.0 and Opera 7.54u1
Does not work in IE 6.0.2900
I believe it does not work in IE because IE tears the page down
(including any script embedded in the page) when you _start_ to navigate
away from the page. Oddly enough, the next example works in IE, I'm sure
there's a perfectly logical explanation for this behaviour (probably has
something to do with when the delegate is bound to the event), but I'm
not going to waste my time thinking about it.
<body onunload="placeholder();">
<script type="text/javascript">
function placeholder() { }
</script>
<button onclick="
window.placeholder = function()
{
alert('Leaving...');
}
">Click this</button>
<a href="
http://www.yahoo.com">Then click this</a>
</body>