0

here is my code:

<iframe src="http://bing.com" style="width:100%; height:500px;"/>
<script>
  $(document.querySelector("iframe").contentWindow.document).on("keydown", function () {
    console.log("prpr")
  })
</script>

when i focus in iframe and hit keyboard, the keydown func isn't be triggered, how to set shortcut for iframe document? Exist sof questions don't fix my question

chikadance
  • 3,591
  • 4
  • 41
  • 73
  • you need to add the handler from inside the framed page, not from "above". Just add a script tag with your code to the framed page. – dandavis Jan 08 '17 at 13:01
  • @dandavis You mean iframe.document.addEventListener? – chikadance Jan 08 '17 at 13:03
  • you be be using `document.addEventListener` from inside the frame. if you can't change the code in the frame, you can't do what you ask. – dandavis Jan 08 '17 at 13:16

0 Answers0