0

I have a moneycounter that shows the amount of money somebody makes per decisec. It works fine but when I switch to another tab or minimize the webpage, the the counting stops. When I come back on the page the counter just resumes. I have not found a similair topic yet, does anybody know how to fix this?

<script>
window.onload = function(){
document.getElementById("maandmoney").value = 2000;
}
var money=0;
var r;
var moneypdsec;
var timer=setInterval(function(){moneyTimer()},100);

function moneyTimer() {

r = document.getElementById("maandmoney").value;
moneypdsec = r / 26297438.3;//months to decisec
money += moneypdsec;
document.getElementById("counter").innerHTML = money.toFixed(4);
}

 function salaris() {
money = 0;
r = document.getElementById("maandmoney").value;
 }
</script>


<textarea id="maandmoney"></textarea>  
<div id="reset"><a href="" onClick="salaris();return false;">R</a>  </div>
<p id="counter">0</p>

fumpr
  • 3
  • 3
  • This has been asked before it seems http://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab-is-inactive-in-chrome – andyw_ Jun 06 '14 at 22:07
  • Different Browser may have different behavior. This post may help also http://stackoverflow.com/questions/15871942/how-do-browsers-pause-change-javascript-when-tab-or-window-is-not-active – nilveryboring Jun 06 '14 at 22:36
  • Thanks! I guess I cannot fix this for Firefox and Chrome. If the interval is rounded to 1000ms my calculations will not be right anymore :/ – fumpr Jun 07 '14 at 08:35

0 Answers0