admin管理员组文章数量:1415100
My iframe content responds to key press, is there a way to send key press into the iframe from the page which contains the iframe?
By the way, the usual way to simulate key press does not work in the scenario:
var ev = $.Event('keypress');
ev.which = 68;
ev.ctrlKey = true;
$('#frame').trigger(ev);
My iframe content responds to key press, is there a way to send key press into the iframe from the page which contains the iframe?
By the way, the usual way to simulate key press does not work in the scenario:
var ev = $.Event('keypress');
ev.which = 68;
ev.ctrlKey = true;
$('#frame').trigger(ev);
Share
Improve this question
asked Nov 18, 2012 at 7:17
user972946user972946
2
- 1 i am sure you are aware of Cross Frame Scripting – NullPoiиteя Commented Nov 18, 2012 at 7:22
- 1 Thank you. Now I see that it is a security concern. You have the right answer. My use case is that I want to send control key and alt key to my shellinabox page from a blackberry phone, which does not have either of those keys. – user972946 Commented Nov 18, 2012 at 7:24
1 Answer
Reset to default 3This is an old question, but I hope this answer is helpful to someone.
There is a new feature in HTML5, window.postMessage, which allows for munication between an iframe and the hosting window. There's some good documentation here.
As usual, you can expect some inconsistencies across browsers: in my experience, Firefox accepts any object as the message, but IE will only accept a string.
There have been some developments to make this feature easy to use in different browsers, including polyfills to make it work in older browsers.
The one that I ended up using was Ben Alman's jquery plugin.
Enjoy!
本文标签: javascriptIs there a way to send keyboard key press to iframe contentStack Overflow
版权声明:本文标题:javascript - Is there a way to send keyboard key press to iframe content? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745151264a2644932.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论