设置 游戏开始时间

cookie.js

function cookiesave(n, v, mins, dn, path)
{
    if(n)
    {
        
        if(!mins) mins = 1 * 24 * 60;    //365 * 24 * 60
        if(!path) path = "/";
        var date = new Date();
        
        date.setTime(date.getTime() + (mins * 60 * 1000));   //365 * 24 * 60* 60 * 1000    365天
    
        //var expires = "2014/9/2 14:21:00";
        var expires = "; expires=" + date.toGMTString();
        
        if(dn) dn = "domain=" + dn + "; ";
        document.cookie = n + "=" + v + expires + "; " + dn + "path=" + path;
    }
}
function cookieget(n)
{
    var name = n + "=";
    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,c.length);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}



//cookiesave('game','1','','',''); function clickclose(){ //点击时进行cookie设置 //document.getElementById('note').style.display='none'; if(cookieget('game')=='1'){ //当点击时,cookie的game值为1时,弹出并设置game值为2 alert("您有3次抢月亮的机会\n请点击继续游戏!"); cookiesave('game','2','','',''); return false; } if(cookieget('game')=='2'){ alert("您还剩下2次机会\n请点击继续游戏"); cookiesave('game','3','','',''); return false; } if(cookieget('game')=='3'){ alert("您还剩下1次机会\n请点击继续游戏"); cookiesave('game','4','','',''); return false; } if(cookieget('game')=='4'){ window.location.href="http://115.29.15.60:8090/qiangyueliang/jieshu.html"; //当cookie的game值为4时,跳出 } }

 

 /*时间判断,未到游戏开始时间,进行跳转*/
 <script>
 
 /*时间判断,未到游戏开始时间,进行跳转*/
 var myDates=Date.parse(new Date());
 var mydates= myDates/1000;
 //var mydates=myDates.toLocaleDateString();  //获取当前时间戳
  
function js_strto_time(str_time){
    var new_str = str_time.replace(/:/g,'-');
    new_str = new_str.replace(/ /g,'-');
    var arr = new_str.split("-");
    var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5]));
    return strtotime = datum.getTime()/1000;
}

var str_time = '2014-09-02 16:00:00';   //限制游戏开始时间 2014-09-02 18:00:00之后
var rst_strto_time = js_strto_time(str_time);

if(mydates <= rst_strto_time){
    window.location.href="http://115.29.15.60/yujingwan/index.html";
}

function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = dd.getMonth()+1;//获取当前月份的日期
    var d = dd.getDate();
    return y+"-"+m+"-"+d;
    }
    


/*设置cookie*/
function gameload(){  //页面加载时,加载cookie
   
   if(cookieget('game')==''){   //当刷新页面时,第一次刷新cookie为空,则设为1
         cookiesave('game','1','','','');               //通过cookie保存一个值
         cookiesave('times',GetDateStr(0),'','','');      //通过cookie保存一个当前的时间
    }   
    if(GetDateStr(0) > cookieget('times')){   //当当前时间大于保存的时间时,即在cookie还没过期之前,重新设置cookie  game 和 times
       cookiesave('game','1','','','');      
       cookiesave('times',GetDateStr(0),'','','');
    }
    
}
window.onload=gameload();
    
</script>  

 

posted @ 2014-11-06 10:20  Shimily  阅读(290)  评论(0)    收藏  举报