I used this code to count down when users were on my site. However it still works (countdown) when I work on another browser tab. Please help me
<style>
#permalink{display:none}
</style>
<script>
if (document.hasFocus())
  {
    var timeleft = 10;
var downloadTimer = setInterval(function(){
  if(timeleft <= 0){
    clearInterval(downloadTimer);
    document.getElementById("countdown").innerHTML = "Done";
    document.getElementById("permalink").style.display = "block";
  } else {
    document.getElementById("countdown").innerHTML = timeleft + " seconds remaining";
  }
  timeleft -= 1;
}, 1000);
  }
</script>
<div id="countdown"></div>
<div class="ebook-buttons">
<span id="download-button"><a id="permalink" href="/download/file.zip" rel="nofollow">Download</a></span>
</div> 
    