Javascript 关于Cookie

来源:互联网 发布:数据库远程连接错误26 编辑:程序博客网 时间:2024/06/05 05:32
function SetCookie(strCookieName,strCookieValue,strExpireDate) {
       var strExpires;
       if(strExpireDate=="session")
        {
            strExpires="";
         }
      else
      {
         if(strExpireDate)
            strExpires=";expires="+strExpireDate;
         else
            strExpires=";expires="+(new Date( (new Date()).getTime() + 1000 * 10 * 60 * 1 )).toGMTString();}
      document.cookie=strCookieName+"="+escape(strCookieValue)+strExpires+";path=/";
  }
 
   function ReadCookie(strCookieName) {
        var anyCookies = document.cookie;
        var pos = anyCookies.indexOf(strCookieName + "=");
        var value = "";
        if (pos != -1) {
            var start = pos + strCookieName.length + 1;
            var end = anyCookies.indexOf(";", start);
            if (end == -1) {
                end = anyCookies.length;
            }
            value = anyCookies.substring(start, end); value = unescape(value);
        }
        return value;
    }
原创粉丝点击