js cookie操作

/*
* Cookie操作
*/
//var domain = "www.ofweekb2b.com";

function setCookie(name, value, expires) {
document.cookie = name + "=" + escape(value)
+ ("; path=/; domain=" + domain)
+ ((expires) ? "; expires=" + expires.toGMTString() : "");
}

function getCookie(name) {
//alert(name);
var prefix = name + "=";
var start = document.cookie.indexOf(prefix);
if (start == -1)
return null;
var end = document.cookie.indexOf(";", start + prefix.length);
if (end == -1)
end = document.cookie.length;
var value = document.cookie.substring(start + prefix.length, end);
value = decodeURIComponent(value)
return value;
}

function deleteCookie(name) {
if (getCookie(name))
document.cookie = name + "=" + ("; path=/; domain=" + domain)
+ ";expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

你可能感兴趣的:(cookie)