発生している問題・エラーメッセージ
カウントダウンがページ遷移するとリセットしてしまう。リセットされないように維持するにはどうすれば良いでしょうか?
該当のソースコード
var
1var cook; 2var cStart2,cEnd2; 3var endtime; 4cook=document.cookie + ";"; 5cStart2 = cook.indexOf("END2=",0); 6if (cStart2 == -1){ 7var endDate = new Date(); 8var endDateAfter = new Date(endDate.getTime() + (1000*60*15)); 9endDate.setTime(endDate.getTime() + (1000*10*1)); 10var mem = endDate.toGMTString(); 11document.cookie = "END2=" + endDateAfter + ";expires=" + mem; 12endtime = endDateAfter; 13} else { 14cEnd2 = cook.indexOf(";", cStart2); 15endtime = cook.substring(cStart2 + 5, cEnd2); 16endtime = Date.parse(endtime); 17} 18function countdownTimer1(){ 19var nowDate = new Date(); 20var period = endtime - nowDate; 21var addZero = function(n){return('0'+n).slice(-2);} 22if(period > 0) { 23var min = Math.floor(period / (1000 * 60)); 24period -= (min * (1000 * 60)); 25var sec = Math.floor(period / 1000); 26period -= (sec * 1000); 27var milli = Math.floor(period / 10); 28var insert = ""; 29insert += '残り時間 <span>00:' + addZero(min) + ':' + '</span>'; 30insert += '<span>' + addZero(sec) + ':' + '</span>'; 31insert += '<span>' + addZero(milli) + '</span>'; 32document.getElementById('timer3').innerHTML = insert; 33setTimeout(countdownTimer1, interval); 34} else { 35var insert = ""; 36insert += ''; 37document.getElementById('timer3').innerHTML = insert; 38} 39} 40function countdownTimer2(){ 41var nowDate = new Date(); 42var period = endtime - nowDate; 43var addZero = function(n){return('0'+n).slice(-2);} 44if(period > 0) { 45var min = Math.floor(period / (1000 * 60)); 46period -= (min * (1000 * 60)); 47var sec = Math.floor(period / 1000); 48period -= (sec * 1000); 49var milli = Math.floor(period / 10); 50var insert = ""; 51insert += '残り時間 <span>00:' + addZero(min) + ':' + '</span>'; 52insert += '<span>' + addZero(sec) + ':' + '</span>'; 53insert += '<span>' + addZero(milli) + '</span>'; 54document.getElementById('timer4').innerHTML = insert; 55setTimeout(countdownTimer2, interval); 56} else { 57var insert = ""; 58insert += ''; 59document.getElementById('timer4').innerHTML = insert; 60} 61} 62countdownTimer1(); 63countdownTimer2();
JavaではなくJavaScriptでは<質問タグ