dimanche 28 janvier 2018

Disable refresh button click for javascript timer

I'm working on the timer module for a quiz project. I have created a timer program it works as expected. But when I click the refresh button the timer restarts. I want the timer to not be affected by the refresh button click. How to achieve this.

<script type ="text/javascript">


var timer = 3600;
var min=0;
var sec = 0;

function starttimer()
{

min=parseInt(timer/60);
sec=parseInt(timer%60);

if(timer<1)

{

window.location="over.html";

}

document.getElementById("time").innerHTML="<b> Time Left: </b>" 
+min.toString()+":"+sec.toString();
timer--;
setTimeout(function(){
starttimer();

},1000);

}
</script>

</head>

<body onload="starttimer();">

<h1> Test Page  </h1>
<div>
<center><b>[<span id="time"></span></b>]</center>
</div>




Aucun commentaire:

Enregistrer un commentaire