getCookie(), setCookie(), deleteCookie() open domain
function getCookie( name ) {
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}function setCookie( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name+"="+escape( value ) +
( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}function deleteCookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

解决方案 »

  1.   

    function GetCookie (name) {  
    var arg = name + "=";  
    var alen = arg.length;  
    var clen = document.cookie.length;  
    var i = 0;  
    while (i < clen) {    
    var j = i + alen;    
    if (document.cookie.substring(i, j) == arg)      
    return getCookieVal (j);    
    i = document.cookie.indexOf(" ", i) + 1;    
    if (i == 0) break;   
    }  
    return null;
    }
    function SetCookie (name, value) {  
    var argv = SetCookie.arguments;  
    var argc = SetCookie.arguments.length;  
    var expires = (argc > 2) ? argv[2] : null;  
    var path = (argc > 3) ? argv[3] : null;  
    var domain = (argc > 4) ? argv[4] : null;  
    var secure = (argc > 5) ? argv[5] : false;  
    document.cookie = name + "=" + escape (value) + 
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
    ((path == null) ? "" : ("; path=" + path)) +  
    ((domain == null) ? "" : ("; domain=" + domain)) +    
    ((secure == true) ? "; secure" : "");
    }
    function DeleteCookie (name) {  
    var exp = new Date();  
    exp.setTime (exp.getTime() - 1);  
    var cval = GetCookie (name);  
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    }
      

  2.   

    net_lover(【孟子E章】):    我SETCOOKIE的代码和你差不多,但是你GETCOOKIE的这段好象有点问题啊。看以下这段:
        if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
    return null;
    }
        我调试的时候,程序运行到这里真的读到了另外网站计数器发出的COOKIE,因此自动跳出函数了。没有达到要读取我网页发出的COOKIE目的。
       
      

  3.   

    net_lover(【孟子E章】):
        你的第2次写的代码,大同小易!
        程序真的读到了另外网站计数器发出的COOKIE。
      

  4.   

    孟子E章,读取Cookie犯得着用那么多力气吗?
    读取Cookie a 的值:
    var a = document.cookie.split("a=")[1].split(";")[0];
    这样多简单
      

  5.   

    var sCookie = document.cookie;
    if(sCookie.indexOf("a=") != -1){
        var a = sCookie.split("a=")[1].split(";")[0];
    }
      

  6.   

    真搞笑,net_lover(【孟子E章】) 和vamzpqde(孟子E章)是不是欧阳锋的左右手互博啊?你们两是不是同1个人啊!
      

  7.   

    net_lover(【孟子E章】)  可是高手耶,都双红钻了!学习一下先!