title: How to tell if browser/tab is active
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active">Is there a way to detect if a browser window is not currently active?</a>  </p>
  </blockquote>
  
  
  
  <p>I have a function that is called every second that I only want to run if the current page is in the foreground, i.e. the user hasn't minimized the browser or switched to another tab. It serves no purpose if the user isn't looking at it and is potentially CPU-intensive, so I don't want to just waste cycles in the background.</p>
  
  <p>Does anyone know how to tell this in JavaScript?</p>
  
  <p>Note: I use jQuery, so if your answer uses that, that's fine :).</p>