admin管理员组文章数量:1334198
Is there any way to listen for keypress events in a parent page while the iframe has focus? Or, alternatively, is it possible to pull away the focus from the iframe?
Please note, the iframe is not within the same domain, so I cannot modify its contents via javascript.
I've tried the following jquery in the parent page, thinking perhaps an intermittent blur would work, but it doesn't seem to.
function iframeBlur(){
$("#iframe").blur();
}
var blurif = setInterval(iframeBlur, 500);
Is there any way to listen for keypress events in a parent page while the iframe has focus? Or, alternatively, is it possible to pull away the focus from the iframe?
Please note, the iframe is not within the same domain, so I cannot modify its contents via javascript.
I've tried the following jquery in the parent page, thinking perhaps an intermittent blur would work, but it doesn't seem to.
function iframeBlur(){
$("#iframe").blur();
}
var blurif = setInterval(iframeBlur, 500);
Share
Improve this question
edited Jan 20, 2015 at 6:57
alex
491k204 gold badges889 silver badges991 bronze badges
asked Apr 9, 2010 at 9:38
MatrymMatrym
17.1k35 gold badges99 silver badges141 bronze badges
1
- I just noticed that setting the focus to an input element works. Is it really the best solution though? I would have to create a hidden input element, and then test to see if other inputs are currently being focused (in which case i shouldn't refocus). – Matrym Commented Apr 9, 2010 at 9:42
2 Answers
Reset to default 5It looks like I just had the wrong syntax. window.focus(); works in ffx and chrome (I've got to resolve other ie bugs first before i know with that).
function iframeBlur(){
window.focus();
}
var blurif = setInterval(iframeBlur, 500);
I'm pretty sure this is not possible, iframes are pretty extensively protected from the parent JavaScript. This is a good thing for security reasons. Otherwise a hacker could register something like gmai1., have a big iframe with the real gmail. and then log password entries from the parent.
本文标签: javascriptListen for keypress while iframe has focusStack Overflow
版权声明:本文标题:javascript - Listen for keypress while iframe has focus? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742325287a2453585.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论