By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,453 Members | 3,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,453 IT Pros & Developers. It's quick & easy.

having trouble with event listener: detect iframe close event fromparent

P: n/a
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
Apr 3 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Apr 3, 11:00 am, Mike Scirocco <m...@yahoo.comwrote:
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);

Apr 3 '07 #2

P: n/a
scripts.contact wrote:
On Apr 3, 11:00 am, Mike Scirocco <m...@yahoo.comwrote:
>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.addEventListe ner('click',temp, false);

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

Mike
Apr 4 '07 #3

P: n/a
On Apr 3, 11:47 pm, Mike Scirocco <m...@yahoo.comwrote:
myIFrame.addEventListener('onclose', temp, false);
myIFrame.contentWindow.document.body.addEventListe ner('click',temp, false);

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

Use attachEvent method for IE or just use onclick=temp
Apr 4 '07 #4

P: n/a
scripts.contact wrote:
On Apr 3, 11:47 pm, Mike Scirocco <m...@yahoo.comwrote:
>>myIFrame.addEventListener('onclose', temp, false);
>myIFrame.contentWindow.document.body.addEventList ener('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
Apr 5 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.