[转载]Cookie应用 - liuliu_刘刘 - 博客园

[转载]Cookie应用 – liuliu_刘刘 – 博客园.

/***设置Cookie记录QQ***/
function SetCookieVerifyingQQ(VerifyingQQ)
{

    var CookieQQ=GetCookieVerifyingQQ();
    
    if(CookieQQ==undefined)
    {
        CookieQQ=VerifyingQQ;
    }
    else
    {
        CookieQQ=CookieQQ+"|"+VerifyingQQ;
    }
    
    //获取当前时间
    var date=new Date();
    var expireDays=1;
    //将date设置为1天以后的时间
    date.setTime(date.getTime()+expireDays*24*3600*1000);
    //将VerifyingQQ设置为1天后过期
    document.cookie="VerifyingQQ="+CookieQQ+";expires="+date.toGMTString();
    
}

/***获取Cookie记录QQ***/
function GetCookieVerifyingQQ()
{
    var strcookie=document.cookie;
    var arrcookie=strcookie.split("; ");
    var VerifyingQQ;
    
    //遍历cookie数组,处理每个cookie对
    for(var i=0;i<arrcookie.length;i++)
    {
          var arr=arrcookie[i].split("=");
          //找到名称为userId的cookie,并返回它的值
          if("VerifyingQQ"==arr[0])
          {
                 VerifyingQQ=arr[1];
                 break;
          }
    }
    return VerifyingQQ;
}
赞(0) 打赏
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏