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.
精彩评论