标签:
贴上一段js操作cookie的方法:
//setCookie
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000)); //day
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires+";path=/";
}
?
//清除cookie
function clearCookie(name) {
setCookie(name, "", -1);
}
?
//获取cookie
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(‘;‘);
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==‘ ‘) c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
}
return "";
}
至于为什么不能操作domain,原因不是很清楚,可能为了安全吧。在服务器端语言均可以操作cookie domain如java python
4.cookie不可跨域访问
?
实现cookie跨域(cookie不可跨域访问)
参考:http://www.iteye.com/topic/1000776
标签:
原文地址:http://www.cnblogs.com/melodi/p/5291557.html