can UnUnload function be added after the page is displayed, or during page creation ?

M

Martin Honnen

Mel wrote:
[Unload]

You can set
window.onunload = function (evt) {

};
with script at any time during page creation or after the page is displayed.
 
G

Grant Wagner

Mel said:
example would be awesome

<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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top