js 跨域名获取 cookie值

setCookie('key','sdas');
function setCookie(name, value) {
        var Days = 30;
        var exp = new Date();
        exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
        document.cookie = name + "=" + value + ";expires=" + exp.toGMTString() + "; path=/" + ";domain=.xx.cn";
    }

/**
* cookie中取值
* */
var a = getCookie('key');
alert(a);
function getCookie (name) {
    var arr,reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //匹配字段
    if (arr = document.cookie.match(reg)) {
        return unescape(arr[2]);
    } else {
        return null;
    }
};

 

你可能感兴趣的:(JavaScript)