Sagewire Logo

having trouble w/event listener to detect iframe close

7 Message(s) by 3 Author(s) originally posted in javascript


From: Mike Scirocco Date:   Tuesday, April 03, 2007
I have an iframe that includes a button:
<input type="button" value="close" onclick="window.close();" />

I'd like to detect the iframe close from the parent window, I was
using this but every time the page loads the close event fires!

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'd be appreciated.

TIA,
Mike


From: Wayne Dobson Date:   Tuesday, April 03, 2007
wrote in message

I have an iframe that includes a button:
<input type="button" value="close" onclick="window.close();" />
I'd like to detect the iframe close from the parent window, I was
using this but every time the page loads the close event fires!
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'd be appreciated.



Would this function call: "temp()", on the line containing this statement:
"myIFrame.addEventListener('onclose', temp(), false);" have anything to do
with it?

--
AKA "Dobbie The House Elf"


From: Mike Scirocco Date:   Tuesday, April 03, 2007
wrote in message:
I have an iframe that includes a button:
<input type="button" value="close" onclick="window.close();" />

I'd like to detect the iframe close from the parent window, I was
using this but every time the page loads the close event fires!

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'd be appreciated.
Would this function call: "temp()", on the line containing this statement:
"myIFrame.addEventListener('onclose', temp(), false);" have anything to do
with it?



I do not know, I thought that was the proper way to attach an event
listener so that when myIFrame fired the onclose event the temp function
was called. Is that wrong?


From: Wayne Dobson Date:   Wednesday, April 04, 2007
wrote in message

wrote in message:
I have an iframe that includes a button:
<input type="button" value="close" onclick="window.close();" />
I'd like to detect the iframe close from the parent window, I was
using this but every time the page loads the close event fires!
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'd be appreciated.

'd this function call: "temp()", on the line containing this
statement: "myIFrame.addEventListener('onclose', temp(), false);" have
anything to do with it?
I do not know, I thought that was the proper way to attach an event
listener so that when myIFrame fired the onclose event the temp function
was called. Is that wrong?



You're supposed to pass a reference, not call the function. Delete the
brackets after the function name.

--
AKA "Dobbie The House Elf"


From: Mike Scirocco Date:   Wednesday, April 04, 2007
wrote in message:
wrote in message:
I have an iframe that includes a button:
<input type="button" value="close" onclick="window.close();" />

I'd like to detect the iframe close from the parent window, I was
using this but every time the page loads the close event fires!

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'd be appreciated.
Would this function call: "temp()", on the line containing this
statement: "myIFrame.addEventListener('onclose', temp(), false);" have
anything to do with it?
I do not know, I thought that was the proper way to attach an event
listener so that when myIFrame fired the onclose event the temp function
was called. Is that wrong?
You're supposed to pass a reference, not call the function. Delete the
brackets after the function name.



Is see, thank you, I did not appreciate the difference.


From: tisomaki Date:   Tuesday, May 22, 2007
Hi,

Just a short correction: myIFrame.addEventListener belongs to NS/
Firefox. Some of the events for NS/Firefox don=B4t contain the prefix
'on' lika onload, onblur etc. For NS/Firefox you gotta define the
event as 'load' or 'unload'

So per my knowledge the correct way to handle this in mozilla'd
be

myIFrame.addEventListener('close', temp, false);

Regards

wrote in message:
wrote in message:
wrote in message:
I have an iframe that includes a button:
<input type=3D"button" value=3D"close" onclick=3D"window.close();" />
I'd like to detect the iframe close from the parent window, I was
using this but every time the page loads the close event fires!
function temp(){
alert('the iframe was closed');
}
function setup(){
var myIFrame =3D document.getElementById("iframe1");
if (myIFrame.addEventListener) {
myIFrame.addEventListener('onclose', temp(), false);
}else if (myIFrame.attachEvent) {
myIFrame.attachEvent ('onclose',temp);
}else{
myIFrame.onclose=3Dtemp();
}
}
window.onload=3Dsetup;
Any suggestions'd be appreciated.
>'d this function call: "temp()", on the line containing this
> statement: "myIFrame.addEventListener('onclose', temp(), false);" have
> anything to do with it?
I do not know, I thought that was the proper way to attach an event
listener so that when myIFrame fired the onclose event the temp functi=
on
was called. Is that wrong?
> You're supposed to pass a reference, not call the function. Delete the
> brackets after the function name.


> Is see, thank you, I did not appreciate the difference.


From: tisomaki Date:   Tuesday, May 22, 2007
Hi,

Just a short correction: myIFrame.addEventListener belongs to NS/
Firefox. Some of the events for NS/Firefox don=B4t contain the prefix
'on' lika onload, onblur etc. For NS/Firefox you gotta define the
event as 'load' or 'unload'

So per my knowledge the correct way to handle this in mozilla'd
be

myIFrame.addEventListener('close', temp, false);

Regards

wrote in message:
wrote in message:
wrote in message:
I have an iframe that includes a button:
<input type=3D"button" value=3D"close" onclick=3D"window.close();" />
I'd like to detect the iframe close from the parent window, I was
using this but every time the page loads the close event fires!
function temp(){
alert('the iframe was closed');
}
function setup(){
var myIFrame =3D document.getElementById("iframe1");
if (myIFrame.addEventListener) {
myIFrame.addEventListener('onclose', temp(), false);
}else if (myIFrame.attachEvent) {
myIFrame.attachEvent ('onclose',temp);
}else{
myIFrame.onclose=3Dtemp();
}
}
window.onload=3Dsetup;
Any suggestions'd be appreciated.
>'d this function call: "temp()", on the line containing this
> statement: "myIFrame.addEventListener('onclose', temp(), false);" have
> anything to do with it?
I do not know, I thought that was the proper way to attach an event
listener so that when myIFrame fired the onclose event the temp functi=
on
was called. Is that wrong?
> You're supposed to pass a reference, not call the function. Delete the
> brackets after the function name.


> Is see, thank you, I did not appreciate the difference.



Next Message: Simple image fader



Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional