开发者

keeping focus on iframe at all times with jquery

开发者 https://www.devze.com 2023-04-07 03:10 出处:网络
I\'ve got an HTML page with an header, a footer, a simple menu and a l开发者_如何学Pythonarge iframe (yeah, i know it\'s sad..)

I've got an HTML page with an header, a footer, a simple menu and a l开发者_如何学Pythonarge iframe (yeah, i know it's sad..)

I need to keep the focus on the iframe at all times (there are keypress events on it), even when clicking on the external parts of the page...

The catch is that i can't access any of the content of the iframe (external site)

How can i accomplish this ? i've been thinking about something like this:

function setFoc(){
  $('#IFRAMEID').focus();
}

setInterval('setFoc()',200)

but i don't like it, it's a really ugly thing to do...

thankssss !

SOLVED: see example here http://jsfiddle.net/GrqkT/1/


Setting click event handler to the body should do the trick.

$("body").click(function(){
  $('#IFRAMEID').focus();
});

It really depeneds on what element are there outside the iframe. Maybe it would be better to rewrite event handlers and send them to iframe?

EDIT:

It won't override other handlers. See example in fiddle here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号