when I do the registration page and send the CAPTCHA countdown, I save the second seconds of the countdown as cookie, so that I can continue to execute the timer when I refresh and leave the page, instead of starting from the heart.
but when I use window.location.href to jump to the page and go back to the registration page, I find that the number of seconds is still the number of seconds I left the page
has anyone solved it?
//
$(".btnStr").click(function(){
var second = 30;
start(second);
})
function start(second){
var timer = setInterval(function(){
if(second>0){
second--;
$(".btnStr").html(second+"");
}else{
$(".btnStr").html("");
clearInterval(timer);
}
setCookie("second",second,1);
},1000)
}
//cookie
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;
}
//cookie
function getCookie(cname){
var name = cname + "=";
var ca = document.cookie.split(";");
for(var i=0; i<ca.length; iPP) {
var c = ca[i].trim();
if (c.indexOf(name)==0) { return c.substring(name.length,c.length); }
}
return "";
}
//cookie
function checkCookie(){
var overplus=getCookie("second");
if (overplus!=0){
start(overplus);
}
}