1

Possible Duplicate:
How do I find out which Javascript element has focus?

Is it possible to check in Javascript whether the current window has focus?

Community
  • 1
  • 1
Andy Hin
  • 30,345
  • 42
  • 99
  • 142

1 Answers1

8

No, not really. May be you could assign handlers to the focus/blur events of the window, setting a boolean to true or false and use that to determine if it has focus or not.

Something along this line:

window.hasfocus = false;

window.onfocus = function(){
   this.hasfocus = true;
}

window.onblur = function(){
   this.hasfocus = false;
}
KooiInc
  • 119,216
  • 31
  • 141
  • 177
  • Great idea, however I would set the standard value to `true`, because when you load the code the window probably already has the focus. – tschoffelen May 08 '13 at 12:13