Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Prevent iframe from stealing focus?

    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

  • #2
    New Coder
    Join Date
    Jan 2009
    Posts
    42
    Thanks
    2
    Thanked 6 Times in 6 Posts
    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.
    Code:
    <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.

  • #3
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jcrypt View Post
    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.
    Code:
    <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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •