views:

122

answers:

2

Does anyone know what to use instead of hasFocus() for Chrome? I want to know when my Chrome tab has focus or not, so I can blink an alert message in the title.

Cheers

A: 

You would use the document.activeElement tag.

NebuSoft
+1  A: 

You could listen for the onfocus/onblur events and keep track of page state that way.

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <div id="output">
    </div>
    <script>
      var has_focus = true;

      function print(str) {
        var out = document.getElementById('output')      
        out.innerText = out.innerText + "\n" + str;
      };

      window.onfocus = function() {
        print('focus');
        has_focus = true;
      };

      window.onblur = function() {
        print('blur');
        has_focus = false;
      };
    </script>
  </body>
</html>
Arne Roomann-Kurrik
thanks i ended up doing somethiing liek this.
sudopal