having trouble with event listener: detect iframe close event fromparent

M

Mike Scirocco

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
 
S

scripts.contact

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);
 
M

Mike Scirocco

scripts.contact said:
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
 
S

scripts.contact

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
 
M

Mike Scirocco

scripts.contact said:
Use attachEvent method for IE or just use onclick=temp

This worked great:

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

Thank You,
Mike
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top