onunload issues

T

Tim Arview

Hi,

I'm trying to create an exit popup that doesn't require anything added
to the body tag. In other words, I don't want to say <body
onunload="foo">. I just want to have window.onunload="foo" in the
<script> tag.

However, when I do that, it launches foo as soon as the page loads and
does NOT launch when the page is unloaded.

Why is this? And is there a way to accomplish what I'm trying to do?

This is a high priority project, so I really need it fixed ASAP.

Thanks for any help you can give me.
 
L

Laurent Bugnion

Hi,

Tim said:
Hi,

I'm trying to create an exit popup that doesn't require anything added
to the body tag. In other words, I don't want to say <body
onunload="foo">. I just want to have window.onunload="foo" in the
<script> tag.

However, when I do that, it launches foo as soon as the page loads and
does NOT launch when the page is unloaded.

Why is this? And is there a way to accomplish what I'm trying to do?

This is a high priority project, so I really need it fixed ASAP.

Thanks for any help you can give me.

You're having syntax problems.

If you use the "onunload" attribute of the body tag, you must use <body
onunload="foo();"> (function call).

If however you assign the foo function to the onunload event, you must
assign the function itself, not a string.

window.onunload = foo;

HTH,
Laurent
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top