Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   having trouble with event listener: detect iframe close event fromparent (http://www.velocityreviews.com/forums/t930530-having-trouble-with-event-listener-detect-iframe-close-event-fromparent.html)

Mike Scirocco 04-03-2007 05:00 PM

having trouble with event listener: detect iframe close event fromparent
 
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

scripts.contact 04-03-2007 08:14 PM

Re: having trouble with event listener: detect iframe close event from parent
 
On Apr 3, 11:00 am, Mike Scirocco <m...@yahoo.com> 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);


Mike Scirocco 04-04-2007 05:47 AM

Re: having trouble with event listener: detect iframe close eventfrom parent
 
scripts.contact wrote:
> On Apr 3, 11:00 am, Mike Scirocco <m...@yahoo.com> 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.addEventListe ner('click',temp, false);

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

Mike

scripts.contact 04-04-2007 05:49 PM

Re: having trouble with event listener: detect iframe close event from parent
 
On Apr 3, 11:47 pm, Mike Scirocco <m...@yahoo.com> wrote:
> > 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



Mike Scirocco 04-05-2007 03:19 AM

Re: having trouble with event listener: detect iframe close eventfrom parent
 
scripts.contact wrote:
> On Apr 3, 11:47 pm, Mike Scirocco <m...@yahoo.com> wrote:
>>> 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


This worked great:

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

Thank You,
Mike


All times are GMT. The time now is 02:41 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.