4

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Marius
  • 57,995
  • 32
  • 132
  • 151

2 Answers2

1

I found the answer in this question. Setting the focus on the document inside the iframe solves the problem

Setting focus to iframe contents

Community
  • 1
  • 1
Marius
  • 57,995
  • 32
  • 132
  • 151
0

I found subscribing the event to window.top worked for me, as my game was several iframes deep.