...

View Full Version : Prevent iframe from stealing focus?



mikembm
01-27-2009, 12:53 AM
I'm working on a site that uses an iframe to load cross domain sites.
The problem is that some sites use javascript to say put focus into an input field.

I have managed to prevent this by using setInterval that continuously gives focus to an input on my page but this causes the problem of not being able to click into the location bar.

So basically, is it possible to to only regain focus when an element inside of the iframe takes focus? Or even just solving the location bar problem with my current solution would also work. (And I have tried things such as applying onfocus events to the iframe element - but they simply don't work because it's not the iframe that's gaining focus, but elements inside of it)

Thanks

jcrypt
01-27-2009, 12:59 AM
Not sure if this will help but you could place an onblur event on the textbox and then cancel the default behavior for the blur event and stop it's propagation.


<input type="text" onblur="event.preventDefault(); event.stopPropagation();"/>

preventDefault and stopPropagation work in FF but I'm not sure if IE supports those two methods. If not I'm sure it provides some type of alternative for canceling default event behavior.

mikembm
01-27-2009, 01:17 AM
Not sure if this will help but you could place an onblur event on the textbox and then cancel the default behavior for the blur event and stop it's propagation.


<input type="text" onblur="event.preventDefault(); event.stopPropagation();"/>

preventDefault and stopPropagation work in FF but I'm not sure if IE supports those two methods. If not I'm sure it provides some type of alternative for canceling default event behavior.


Tried out the code you posted but it doesn't work :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum