How do you test if the browser has focus?
Join Stack Overflow to learn, share knowledge, and build your career.
|
I haven't tested this in other browsers, but it seems to work in Webkit. I'll let you try IE. :o) Try it out: http://jsfiddle.net/ScKbk/ After you click to start the interval, change the focus of the browser window to see the result change. Again, tested only in Webkit.
|
|||||||||||||||||||||
|
|
use the hasFocus method of the document. You can find detailed description and an example here: hasFocus method EDIT: Added fiddle http://jsfiddle.net/Msjyv/3/ HTML
JS
|
|||||||||||||||||||||
|
|
HTML:
Javascript:
UPDATE: I'll fix it, but IE does not work very well |
|||||||||
|
document.hasFocus(), which returns a boolean. It's built into the spec, so it can be done without jQuery. – Braden Best Feb 4 '13 at 21:41