Salve ragazzi,
Da totalmente inesperto, sto cercando il codice di un conto alla rovescia. Ne ho trovati diversi ed il più valido mi sembra questo:
L'unico motivo per il quale non riesco ad utilizzarlo è che al momento di inserire il codice html, il timer compare a capo. Allego un'immagine per far capire meglio il risultato che desidero. Grazie a chiunque vorrà aiutarmi.codice:var timeoutHandle;function countdown(minutes,stat) { var seconds = 60; var mins = minutes; if(getCookie("minutes")&&getCookie("seconds")&&stat) { var seconds = getCookie("seconds"); var mins = getCookie("minutes"); } function tick() { var counter = document.getElementById("timer"); setCookie("minutes",mins,10) setCookie("seconds",seconds,10) var current_minutes = mins-1 seconds--; counter.innerHTML = current_minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds); //save the time in cookie if( seconds > 0 ) { timeoutHandle=setTimeout(tick, 1000); } else { if(mins > 1){ // countdown(mins-1); never reach “00″ issue solved:Contributed by Victor Streithorst setTimeout(function () { countdown(parseInt(mins)-1,false); }, 1000); } } } tick(); } function setCookie(cname,cvalue,exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires=" + d.toGMTString(); document.cookie = cname+"="+cvalue+"; "+expires; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1); if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } countdown(2,true);
PS. L'html è questo:E vorrei se fosse possibile qualcosa del tipo:codice:<div id="hms">00:10:10</div>codice:<div id="hms"><p>Ore rimaste:00:10:10</div>/p>

Rispondi quotando

