views:

254

answers:

2

Is there any way to listen for keypress events in a parent page while the iframe has focus? Or, alternatively, is it possible to pull away the focus from the iframe?

Please note, the iframe is not within the same domain, so I cannot modify it's contents via javascript.

I've tried the following jquery in the parent page, thinking perhaps an intermittent blur would work, but it doesn't seem to.

function iframeBlur(){
    $("#iframe").blur();         
}
var blurif = setInterval(iframeBlur, 500);

Thanks for your time!

A: 

I'm pretty sure this is not possible, iframes are pretty extensively protected from the parent JavaScript. This is a good thing for security reasons. Otherwise a hacker could register something like gmai1.com, have a big iframe with the real gmail.com and then log password entries from the parent.

Franz
A: 

It looks like I just had the wrong syntax. window.focus(); works in ffx and chrome (I've got to resolve other ie bugs first before i know with that).

function iframeBlur(){
    window.focus();  
}
var blurif = setInterval(iframeBlur, 500);
Matrym
Won't this set focus to window every 500 milliseconds?
rahul
Yeah, the downside is that this prevents any typing in the iframe window. The upside is that it allows for shortcuts via keys in the parent window. It's definitely less than ideal, so I'm open minded to other solutions.
Matrym
Won't this also prevent the user from using any other programs on their machine, too? If the browser is coming to the front every 500ms, the whole machine will be unsuable for anything except your page...
John Yeates