Javascript examples for DOM:Document hasFocus
The hasFocus() method returns the document has focus.
None
A Boolean value, whether the document has focus
The following code shows how to Output some text if the document has focus:
<!DOCTYPE html> <html> <body> <p id="demo"></p> <script> setInterval("myFunction()", 1); function myFunction() {//w ww. j ava2 s. co m var x = document.getElementById("demo"); if (document.hasFocus()) { x.innerHTML = "The document has focus."; } else { x.innerHTML = "The document DOES NOT have focus."; } } </script> </body> </html>