I have a text field that I would like to maintain focus, no matter what.
The problem is, my page loads an iframe (cross domain), the contents of which steal the focus. What's more, the user might be typing in my text field as the iframe steals focus, causing the user to type in the iframe's text field instead.
I've tried spamming the .focus() event, in the hopes that if it gets blurred, it will refocus near instantly. It seems like this would work, but what happens is it doesn't switch focus back fast enough -- the user is still able to type in the iframe's focused field.
Is there a way to prevent blur from occurring at all? Or a faster way to switch focus back to my text field?
Here's what I've tried, which doesn't work completely:
//get the textbox DOM element to focus.
var my_textbox = $("#my_textbox").get(0);
//pretty straight-forward -- focus it.
var setFocus = function(){
my_textbox.focus();
}
//every 10ms refocus our textbox.
//apparently, 10ms is not fast enough, as some typing
//still occurs in the iframe's textfield.
setInterval(setFocus, 10);
Note: I did just as a similar question yesterday, but I think this one gets to the root of the problem. I hope it's ok.
Thanks for your help, any ideas are appreciated.