title: How to get javascript Timer to stop when not viewing tab/window
body: <p>I am running a page with a timer that I'm using to run in a iframe of a page so that I know that someone was on there actually with window in focus paying attention to screen and if leave have the timer pause until back viewing the window or in focus.</p>
  
  <p>I have 4 timer files: timer.css timer.js timer.php &amp; timerb.js</p>
  
  <p>I believe I would execute it in the following file and code, but that is where I am stuck as don't know what or where to add it for sure and no luck yet and why here asking so please take a look and let me know if you can help.</p>
  
  <p>File: timer.js</p>
  
  <pre><code>function adTimer() {
    timer++;
    if(timer == fulltimer) {
      var show="Click "+key;
      $("#buttons").fadeIn();
      $("#timer").html(show);
    }
    else {
      setTimeout(adTimer, 1000);
    }
    $("#bar").width((timer/fulltimer)*200);
  }
  </code></pre>