Keypress inside iFrame


(edgar) #1

Hei all,

My documents keypresses work fine in the exported html file but when embedded inside an iFrame the keypresses stop working. Even after I click inside the iframe and interact with the objects in it.

I have it implemented through OnSceneLoad with this script:

[details=script]
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == ‘39’) {
// right arrow
hypeDocument.showSceneNamed(‘scene04_00’,hypeDocument.kSceneTransitionPushRightToLeft);
}
else if (e.keyCode == ‘37’) {
// left arrow
hypeDocument.showSceneNamed(‘scene02_00’,hypeDocument.kSceneTransitionPushLeftToRight);
}
}[/details]

Any ideas how to get it working inside an iFrame? For me it’s strange that clicking/focusing inside the iframe does not make it work.

Thanks,
Edgar

Edit:
Surprisingly pressing TAB inside the iframe makes all the keypresses work again. Is there anyway to do this on the documents load?


(Hans-Gerd Claßen) #2

just a guess:
use hypes onkeydown instead of sceneload and reduce your code to …

if (event.keyCode == '39') { // right arrow hypeDocument.showSceneNamed('scene04_00',hypeDocument.kSceneTransitionPushRightToLeft);}else if (event.keyCode == '37') { // left arrow hypeDocument.showSceneNamed('scene02_00',hypeDocument.kSceneTransitionPushLeftToRight);}


(Jonathan Deutsch) #3

You’d need to bind to the parent window/document instead of the iframe one. This is a common problem so there’s some methods if you search “iframe keydown” like: