function setCookie(name, value, day, path, domain){
day = day || 30;
path = path || '/';
var str = name + '=' + value + '; ';
if(day) str += 'expires=' + new Date(Date.now() + day * 24 * 3600 * 1000).toGMTString() + '; ';
if(path) str += 'path=' + path + '; ';
if(domain) str += 'domain=' + domain;
document.cookie = str;
};
//使用
var token='token'
setCookie('token',token,1,'/','http://127.0.0.1:8080')
setCookie('token',token,1,'/','')
setCookie('token',token,1,'/','http://127.0.0.1:8182')
备注:
1.本地测试不能使用localhost,否则没有效果