Javascript 如何设置iframe作用域快捷方式
这是我的密码:Javascript 如何设置iframe作用域快捷方式,javascript,jquery,iframe,Javascript,Jquery,Iframe,这是我的密码: <iframe src="http://bing.com" style="width:100%; height:500px;"/> <script> $(document.querySelector("iframe").contentWindow.document).on("keydown", function () { console.log("prpr") }) </script> $(document.querySel
<iframe src="http://bing.com" style="width:100%; height:500px;"/>
<script>
$(document.querySelector("iframe").contentWindow.document).on("keydown", function () {
console.log("prpr")
})
</script>
$(document.querySelector(“iframe”).contentWindow.document)。在(“keydown”上,函数(){
控制台日志(“prpr”)
})
当我在iframe中聚焦并点击键盘时,不会触发keydown功能,如何设置iframe文档的快捷方式?存在sof问题不修复我的问题您需要从框架页面内部添加处理程序,而不是从“上面”添加。只需将带有代码的脚本标记添加到框架页面。@dandav您是指iframe.document.addEventListener吗?您将从框架内部使用
document.addEventListener
。如果无法更改框架中的代码,则无法按要求执行。