onunload issues

Discussion in 'Javascript' started by Tim Arview, Dec 17, 2006.

  1. Tim Arview

    Tim Arview Guest

    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.
     
    Tim Arview, Dec 17, 2006
    #1
    1. Advertisements

  2. Hi,

    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
     
    Laurent Bugnion, Dec 17, 2006
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.