Listen for keystrokes while the iframe has focus?

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

Please note: iframe is not within the same domain, so I can not change its contents using javascript.

I tried the following jquery on the parent page, thinking that intermittent blur could happen, but that doesn't seem to be the case.

function iframeBlur(){ $("#iframe").blur(); } var blurif = setInterval(iframeBlur, 500); 
+4
source share
2 answers

It looks like I had the wrong syntax. window.focus (); works in ffx and chrome (I need to solve other errors before I find out about this).

 function iframeBlur(){ window.focus(); } var blurif = setInterval(iframeBlur, 500); 
+3
source

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

+1
source

Source: https://habr.com/ru/post/1306458/


All Articles