Detecting whether a window is active

Discussion in 'JavaScript' started by yleiko, Aug 1, 2008.

  1. #1
    Is there a way detecting a window is active or not.

    Let me explain a little bit more.
    For example DP window is currently active on my browser, and my webpage is in another tab (or other browser window) and is inactive.
    I want to detect with a javascript whether my site is currently used by the user or it is on the background
     
    yleiko, Aug 1, 2008 IP
  2. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In the example above:
    The page turns white if focused and gray if blured...

    <html>
      <head>
        <script type="text/javascript">
          window.onblur = function ()
          {
            document.body.style.backgroundColor = "#CCCCCC";
          }
          window.onfocus = function ()
          {
            document.body.style.backgroundColor = "#FFFFFF";
          }
        </script>
      </head>
    
      <body style="background-color=#FFFFFF">
      </body>
    </html>
    HTML:
     
    selling vcc, Aug 1, 2008 IP
  3. yleiko

    yleiko Peon

    Messages:
    74
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    works perfect

    thanks
     
    yleiko, Aug 1, 2008 IP
    selling vcc likes this.