having trouble with event listener: detect iframe close event fromparent

Discussion in 'Javascript' started by Mike Scirocco, Apr 3, 2007.

  1. I have an iframe that includes a button:
    <input type="button" value="close this window" onclick="window.close();" >

    I would like to detect the iframe close event from the parent window, I
    was using this code but I did something wrong because the temp function
    is fired every time the parent page loads:

    function temp(){
    alert('the iframe was closed');
    }
    function setup(){
    var myIFrame = document.getElementById("iframe1");
    if (myIFrame.addEventListener) {
    myIFrame.addEventListener('onclose', temp(), false);
    }else if (myIFrame.attachEvent) {
    myIFrame.attachEvent ('onclose',temp);
    }else{
    myIFrame.onclose=temp();
    }
    }
    window.onload=setup;

    Any suggestions would be appreciated.

    TIA,
    Mike
    Mike Scirocco, Apr 3, 2007
    #1
    1. Advertising

  2. Re: having trouble with event listener: detect iframe close event from parent

    On Apr 3, 11:00 am, Mike Scirocco <> wrote:
    > I have an iframe that includes a button:
    > <input type="button" value="close this window" onclick="window.close();" >
    >
    > I would like to detect the iframe close event from the parent window, I
    > was using this code but I did something wrong because the temp function
    > is fired every time the parent page loads:
    >
    > function temp(){
    > alert('the iframe was closed');}
    >
    > function setup(){
    > var myIFrame = document.getElementById("iframe1");
    > if (myIFrame.addEventListener) {
    > myIFrame.addEventListener('onclose', temp(), false);


    myIFrame.addEventListener('onclose', temp, false);
    scripts.contact, Apr 3, 2007
    #2
    1. Advertising

  3. Re: having trouble with event listener: detect iframe close eventfrom parent

    scripts.contact wrote:
    > On Apr 3, 11:00 am, Mike Scirocco <> wrote:
    >> I have an iframe that includes a button:
    >> <input type="button" value="close this window" onclick="window.close();" >
    >>
    >> I would like to detect the iframe close event from the parent window, I
    >> was using this code but I did something wrong because the temp function
    >> is fired every time the parent page loads:
    >>
    >> function temp(){
    >> alert('the iframe was closed');}
    >>
    >> function setup(){
    >> var myIFrame = document.getElementById("iframe1");
    >> if (myIFrame.addEventListener) {
    >> myIFrame.addEventListener('onclose', temp(), false);

    >
    > myIFrame.addEventListener('onclose', temp, false);


    Removing the parens works great in FF, thanks:

    myIFrame.contentWindow.document.body.addEventListener('click',temp, false);

    Do you have any suggestions about making this work in IE?

    Mike
    Mike Scirocco, Apr 4, 2007
    #3
  4. Re: having trouble with event listener: detect iframe close event from parent

    On Apr 3, 11:47 pm, Mike Scirocco <> wrote:
    > > myIFrame.addEventListener('onclose', temp, false);


    > myIFrame.contentWindow.document.body.addEventListener('click',temp, false);
    >
    > Do you have any suggestions about making this work in IE?
    >



    Use attachEvent method for IE or just use onclick=temp
    scripts.contact, Apr 4, 2007
    #4
  5. Re: having trouble with event listener: detect iframe close eventfrom parent

    scripts.contact wrote:
    > On Apr 3, 11:47 pm, Mike Scirocco <> wrote:
    >>> myIFrame.addEventListener('onclose', temp, false);

    >
    >> myIFrame.contentWindow.document.body.addEventListener('click',temp, false);
    >>
    >> Do you have any suggestions about making this work in IE?
    >>

    >
    >
    > Use attachEvent method for IE or just use onclick=temp


    This worked great:

    myIFrame.contentWindow.document.body.onclick=temp;

    Thank You,
    Mike
    Mike Scirocco, Apr 5, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AndiArt

    jsp: listener on session close

    AndiArt, Jun 13, 2008, in forum: Java
    Replies:
    7
    Views:
    931
    Andrew Thompson
    Jun 29, 2008
  2. Iñaki Baz Castillo
    Replies:
    7
    Views:
    849
    Iñaki Baz Castillo
    Jan 12, 2010
  3. Daedalous
    Replies:
    3
    Views:
    687
    Daedalous
    Jan 16, 2004
  4. hyejin
    Replies:
    8
    Views:
    337
    Martin Honnen
    Aug 29, 2006
  5. Replies:
    0
    Views:
    494
Loading...

Share This Page