开发者

Onkeydown event not working when focused on Iframe

How can I get this code to execute even when the focused on the iframe?

<Script>
  function check(){ alert("test"); }
</script>

<body onkeydown="check()";>
  Onkeydown event only works when focus is not on ifram开发者_运维知识库e...<br>
<iframe src="about:blank" frameborder=1;> </iframe>


If the iframe is on a different domain than the hosting site you are out of luck. If not and you don't have control over it, you are out of luck. Else you could modify the iframe page to listen for the onkeydown event and invoke a parent javascript function:

window.parent.check();


The iframe represents a different document and DOM events (e.g. key events) only bubble up within the same document. You will have to attach an additional key down listener to the iframe document.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜