Calling onunload in frameset

Discussion in 'Javascript' started by Andrew Poulos, Mar 23, 2005.

  1. In a frameset I have this:

    window.onload = function() {
    frames[1].onunload = function() {
    alert('I'm going now');
    }
    }

    when frames[1] unloads I'm expecting the alert to be called but it never
    does. If, instead, I put this into frames[1] it does call the alert:

    window.onunload = function() {
    alert('I'm also going now');
    }

    How can I get it to work from the frameset?

    Andrew Poulos
     
    Andrew Poulos, Mar 23, 2005
    #1
    1. Advertisements

  2. Andrew Poulos

    Csaba2000 Guest

    As I understand your question, your example code is saying, put an onload
    handler on my frame as I'm [= the frameset] unloading myself. But by then
    I'd expect my frame to already be gone. To double check this, also put
    an alert before the frames[1].onunload = function() ... statement.

    Csaba Gabor from Vienna
     
    Csaba2000, Mar 24, 2005
    #2
    1. Advertisements

  3. I think I didn't state my problem unambiguously. Let me try again:

    Without putting any script into each frame how can a frameset detect
    events, such as onload and onunload, from each frame (as opposed to the
    entire frameset)?

    Andrew Poulos
     
    Andrew Poulos, Mar 24, 2005
    #3
  4. Andrew Poulos

    Csaba2000 Guest

    I would try (not that I have, mind you):
    Put into the <head> section of the frameset page:
    <script type='text/javascript'>
    function myFunc() { alert("Here I am"); }
    top.onload = top.setTimeout(function() {
    top.frames[1].onunload = top.myFunc; }, 100)
    </script>

    the setTimeout business is because it may be that the frameset's onload
    fires when the page is read in and not after all the frames have loaded.
    If you determine which it is, it would be good if you would let the group
    know - and perhaps you can relax part of the above code (if it works
    at all, that is).

    Also, when you are doing anything with functions across frames it is a
    good idea to fully qualify them (ie, appropriateWindow.functionName)

    Csaba
     
    Csaba2000, Mar 24, 2005
    #4
    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.