This forum is read only and just serves as an archive. If you have any questions, please post them on

8 years ago by Blammo

I'm having an unusual issue with impact whenever I have the canvas running from within an iframe and I bind the left mouse button to an action. I think I might know what's causing it too.

Currently I'm writing a game that involves a few keyboard actions and the mouse, and it runs inside an iframe for reasons I won't go into. Running it outside the iframe isn't an option, sorry. =/

If the game starts inside the iframe, it doesn't have focus, so none of the keys work, which is fine because you only see the title screen until you click something anyway. Normally, I can select the iframe with the left mouse button which will focus it and make everything work If I bind the left mouse button to an action in the game, though, the focus doesn't happen, so the mouse action works but none of the keyboard actions do.

No matter what I do, I can't focus the canvas. I've even tried calling .focus() on it inside my game code on the mouse button action, but that doesn't work either.

Any ideas? (Don't say don't run it in an iframe ¬_¬ )

8 years ago by dominic

Don't run it in an iframe :F

The issues probably stems from the fact that Impact calls event.preventDefault() when receiving keyboard or mouse input. This may block the normal focus() action.

Try calling .focus() yourself on the window or body element, not the canvas. Maybe this helps:

8 years ago by Blammo

Thanks, it worked =D

8 years ago by jizaymes

For posterities sake, the way I overcame this issue was as follows:

in my outer index.html (not the iframe), change the traditional <body> tag to

<body onload="document.getElementById('ifr').contentWindow.focus();">

Rest of the iframe is defined as
 <iframe id=ifr src="innerIndex.html" WIDTH="768" HEIGHT="480"></iframe>
Page 1 of 1
« first « previous next › last »