John Smith
John Smith

Reputation: 6197

Javascript: passing keypress event to an iframe

I have a basic HTML design with an IFRAME in it, and if I want to work the scrolling with arrows/page up,down, first I have to focus the iframe. Instead, I want to "forward" the keypress events to it. In :

<script>
document.onkeypress = function(e) {
    top.frames['iframe'].document.onkeypress(e);
}
</script>

but this doesnt work. I must not use jQuery!

Upvotes: 1

Views: 1665

Answers (1)

ShufflebuyLLC
ShufflebuyLLC

Reputation: 68

There is a new feature in HTML5, "window.postMessage", which allows for communication between an iFrame and the hosting window.

There's some good documentation on the Mozilla Developer Center - window.postMessage page.

//Syntax
otherWindow.postMessage(message, targetOrigin, [transfer]);

Upvotes: 5

Related Questions