title: Is there a way to detect if a browser window is not currently active?
body: <p>I have JavaScript that is doing activity periodically. When the user is not looking at the site (i.e., the window or tab does not have focus), it'd be nice to not run.</p>
  
  <p>Is there a way to do this using JavaScript?</p>
  
  <p>My reference point: Gmail Chat plays a sound if the window you're using isn't active. </p>