javascript - Detecting when an iframe gets or loses focus -


What is the correct way to detect when there is an iframe or loses focus (i.e. the keyboard event will not be found) ? The following is not working in Fx4:

  var iframe = / * my iframe * /; Iframe.addEventListener ("Focus", function ()) / / is never called * false,); You can choose "document.activeElement" to determine if it matches an iframe    

Polling is not ideal, but it works:

  function check focus () {if (document.activeElement == document.getElementsByTagName ("iframe") [ 0]) {console.log ('Iframe Focus'); } Else {console.log ('iframe not centered'); }} Window.setInterval (Check Focus, 1000);    

Comments