Listening for window.close event issued from within an iFrame?

I have a div that contains an iframe. The page contained within the iframe has an image that uses javascript:window.close(). I want to listen for that call from that image within that iframe (or perhaps the onclick on that particular image?) to then call a function in the main parent page. How do I pass the events that occur in the document within the iFrame up to the parent? Or if I need to add a listener for the onclick event on the image within the iFrame, how does that get back up to the parent?

The hierarchy is like this:
PARENT DOCUMENT

[INDENT]DIV

[INDENT]IFRAME

[INDENT]DOCUMENT

[INDENT]TABLE

IMAGE (a href=“javascript:window.close();”)[/INDENT][/INDENT][/INDENT]

[/INDENT]

How do I get that “window.close” call or the onclick event on the image that calls it, sent back up to the parent document so that I can call my custom function?

Thanks in advance. I think I’ve been looking at this too long and have managed to confuse something that might not be complicated!

How do I get that “window.close” call or the onclick event on the image that calls it, sent back up to the parent document so that I can call my custom function?

window.onunload may be the event you want to react to.

You don’t send the event to the parent. When the event fires in the iframe, you use js in the iframe to call the function in the parent. In any window, when you call a function on the same page, you are really doing this:

window.myFunc();

So, when you call the function from your iframe, you need to replace ‘window’ with a reference to the window containing the function. In your case, that is parent.

I see. I don’t have direct access to the page that loads into the iframe, hence my initial thought that I needed to add a listener in the parent for the close() event in the iframe. The page that is being loaded into the iframe is normally a aspx-based page that is called in a popup window (I know, I know…not my choice either). So now I’m trapping it in a div that is draggable (a la Scriptaculous and Prototype) and I want to be able to “listen” for the click on the “close window” image that would have normally closed the popup window, only this time I want it to trigger a fade effect function on the containing div since the close() will be ignored by the page due to it now being in an iframe rather than a popup window.
Clear as mud…

Anyway, I appreciate the help. I’ll see what’s available regarding that “popup” window file…