title: Check if site is in foreground
body: <p>I would like to check if my website is in foreground with JavaScript. But don't answer before reading everything because you would directly say to me that I should do <a href="http://jsfiddle.net/cK3NU/" rel="nofollow">this</a>:</p>
  
  <pre><code>$(window)
      .focus(function() {
          console.log("focus");
      })
      .blur(function() {
          console.log("blur");
      });​
  </code></pre>
  
  <p>But the problem is that I've got an iframe from a third party on my page and if the user clicks on the iframe the window blur event gets fired but the user is acctualy still on my page. I tried to fix this by checking <a href="http://jsfiddle.net/cK3NU/1/" rel="nofollow">if <code>document.activeElement</code> is an iframe on blur</a>:</p>
  
  <pre><code>$(window)
      .focus(function() {
          console.log("focus");
      })
      .blur(function() {
          console.log("blur");
          if (document.activeElement.tagName.toLowerCase() == "iframe") {
              console.log("still focus");
          }
      });​
  </code></pre>
  
  <p>The problem here is that I'm not able to check if the page is not in foreground anymore when a user clicks on the iframe first and then on another application.</p>
  
  <p>So how can I check if the site is in foreground when it got an iframe in it?</p>