Forum Moderators: open

Message Too Old, No Replies

Initiate Script for <iframe> onFocus

         

otem

2:15 am on Feb 10, 2007 (gmt 0)

10+ Year Member



Hello,

On my site, I have two iframes containing links.

If a user clicks one of these links, I would like to run a script.

This is what I have so far, but it doesn't seem to be working:

<script type="text/javascript">
document.getElementsByTagName("iframe").onfocus=function(){
...
}
</script>

Any ideas what I'm doing wrong?

Thanks.

daveVk

3:30 am on Feb 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.getElementsByTagName("iframe").onfocus=function()

which document? I think in this case it refers to the iframe document that does not contain itself!

You need to use w.document where w is the main window.

Or maybe just window.onfocus=function() as window is the current iframe?

otem

4:14 pm on Feb 10, 2007 (gmt 0)

10+ Year Member



Thanks Dave for your response.

I haven't tried using window instead of document, so I'll give it a try, but I actually just found out that onfocus for iframes is not a valid protocol, so it looks like I'll have to try something radically different.

But thanks again.

kaled

11:56 am on Feb 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.getElementsByTagName("iframe") returns an array (of iframe elements). I believe you should iterate through the array and assign the onfocus event for each element.

Kaled.