C
Christine
I've implemented a countdown timer for a tutorial web page that should
give the user 45 minutes to complete the test, only to find that the
timer is slowly 'losing' time. On average, it actually takes an extra
35 seconds, but has taken an extra 2.5 minutes in some cases. Any
ideas what might be the cause? And more importantly - the fix? Code
snippet below...
Thanks,
Christine
var gTimer=null;
var gTimerCount = 2700; //45 minutes
function CallTimer(num){ //this function is called when the page
is loaded
gTimerCount=num;
Timer();}
function Timer() {
window.status="";
gTimerCount--;
if (gTimerCount > 0)
{
if (gTimerCount == 300) TimeWarning();
window.status = "Time Remaining: " +
ConvertNum(gTimerCount) + " CT " + timeValue + " CTsecs " + ((hours *
3600)+(minutes * 60)+seconds);
gTimer=window.setTimeout("Timer()",1000);
}
else{
//OpenWin.close();
window.document.forms[0].submit.click();}
}
function ConvertNum(numsecs) { return (Math.floor(numsecs/60)) +
":" + AdjustNum(numsecs % 60); }
function AdjustNum(numsecs) {
if (numsecs < 10) return "0"+ numsecs;
else return numsecs;
}
give the user 45 minutes to complete the test, only to find that the
timer is slowly 'losing' time. On average, it actually takes an extra
35 seconds, but has taken an extra 2.5 minutes in some cases. Any
ideas what might be the cause? And more importantly - the fix? Code
snippet below...
Thanks,
Christine
var gTimer=null;
var gTimerCount = 2700; //45 minutes
function CallTimer(num){ //this function is called when the page
is loaded
gTimerCount=num;
Timer();}
function Timer() {
window.status="";
gTimerCount--;
if (gTimerCount > 0)
{
if (gTimerCount == 300) TimeWarning();
window.status = "Time Remaining: " +
ConvertNum(gTimerCount) + " CT " + timeValue + " CTsecs " + ((hours *
3600)+(minutes * 60)+seconds);
gTimer=window.setTimeout("Timer()",1000);
}
else{
//OpenWin.close();
window.document.forms[0].submit.click();}
}
function ConvertNum(numsecs) { return (Math.floor(numsecs/60)) +
":" + AdjustNum(numsecs % 60); }
function AdjustNum(numsecs) {
if (numsecs < 10) return "0"+ numsecs;
else return numsecs;
}