日期:2014-05-16  浏览次数:20375 次

chrome下cookie设置问题
HTML code

setCookie("user",40);
var a = getCookie("user");
alert(a);
function getCookie(name) {   
    var arg = name + "=";   
    var alen = arg.length;   
    var clen = window.document.cookie.length;   
    var i = 0;   
    while (i < clen) {   
       var j = i + alen;   
       if (window.document.cookie.substring(i, j) == arg)    
           return getCookieVal (j);   
        i = window.document.cookie.indexOf(" ", i) + 1;   
        if (i == 0)    
          break;   
   }   
   return null;   
}   
   
function getCookieVal (offset) {   
    var endstr = window.document.cookie.indexOf (";", offset);   
    if (endstr == -1)    
         endstr = window.document.cookie.length;   
    return unescape(window.document.cookie.substring(offset, endstr));   
}   
  
   
function setCookie (name, value) {   
    var exp = new Date();   
    exp.setTime(exp.getTime() + (30*24*60*60*1000));   
    window.document.cookie = name + "=" + escape (value)+ ";expires=" + exp.toGMTString()+";path=/";   
}
   
function deleteCookie (name) {   
    var exp = new Date();   
    exp.setTime (exp.getTime() - 1);   
    var cval = getCookie (name);   
    window.document.cookie = name + "=" + cval + "; expires=" +  exp.toGMTString()+";path=/";   
}  



在google chrome运行,alert的是NULL值
setCookie("user",40);报错

------解决方案--------------------
JScript code

没有看你的代码,如果你在别的浏览器运行正常,而在google下出错,
那估计就是你忽略了.Chrome浏览器为了安全只支持online-cookie也就是,本地不可以
所以你可以上传到FTP上 再试下应该是可以的