cookie跨域存储

//存储cookie,这里的域名必须是顶级域名
setCookie('age','18','baidu.com','15')
function setCookie(cName, value,domain,expireDate) {
	const exDate = new Date();
	exDate.setDate(exDate .getDate() + expireDate);
	document.cookie = cName + "=" + decodeURIComponent(value) + (expireDate== null ? "" : ";expires=" + exDate.toUTCString()) + ";path=/;domain="+domain;
}

//获取cookie
getCookie('age')
function getCookie(key) {
    return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(key).replace(/[-.+*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
}

你可能感兴趣的:(java,数据库,服务器)