'How can an element inside an iframe capture a key event?
I have a canvas element in a simple html document with an attached keydown and keyup listener. This works correctly when I load the document in the browser and start pressing the keys. However, if I load the document in an iframe, nothing happens when I press the keys. It seems the key events never enter the iframe or the document inside the iframe. Is there a way to fix this?
Solution 1:[1]
I found the answer in this question. Setting the focus on the document inside the iframe solves the problem
Solution 2:[2]
I found subscribing the event to window.top worked for me, as my game was several iframes deep.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | Shane Skuse |
