Hello all,
I have a javascript code with a countdown timer that runs on the client side and is updated regularly to the date set in mysql db.
I want to make the timer stop when the internet connection is lost.
Any ideas ? I am thinking on using clearTimeout()…but I need to associate it with the internet connection.
Here is the script:
function countdown(vid)
{
var acao;
var divs;
Timer=Timer+1;
if((Timer%10==”0″)||(Timer==”1″)){
$.get(“current.php”, {
id:vid},
function(data){
acao=data.split(“||”);
for(n=0;n<=acao.length;n++)
{
if(acao[n] != undefined)
{
divis=acao[n].split(“##”);
$(‘#futu’+divis[0]).html(divis[1]);
}}
});
}
var cvid=”vid”;
var tacao=vid.split(“|”);
for(i=0;i<=tacao.length;i++)
{
if(tacao[i] != undefined)
{
var dd=$(‘#futu’+tacao[i]).text();
var paus=$(‘#pause’+tacao[i]).text();
var cdd=dd-1;
$(‘#futu’+tacao[i]).html(cdd);
dd=dd*1000;
dday=Math.floor(dd/(60*1000*1)
dhour=Math.floor((dd%(60*1000*60*1)
dmin=Math.floor(((dd%(60*1000*60*1000)
dsec=Math.floor((((dd%(60*60*24))%(60*1000))%(60
if(dday==0&&dhour==0&&dmin==0&&dsec==0){
$(‘#Us’+tacao[i]).html(“Vend”);
//return
}
if(dhour <=9)
{
dhour = “0”+dhour;
}
if(dmin <=9)
{
dmin = “0”+dmin;
}
if(dsec <=9)
{
dsec = “0”+dsec;
}
if(paus==’yes’)
{
var valll=”Paused”;
}
if(dd>=0)
{
var valll=dhour+”:”+dmin+”:”+dsec;
}
if(dd<0)
{
var valll=”End”;
}
if(dd<11000)
{
var valll=”<font color=red>”+valll+”</font>”;
}
$(‘#Us’+tacao[i]).html(valll);
}}
refreshID=setTimeout(“countdown(‘”+vid+”‘)”,1000);
}