<---------------------------设置Cookie-------------------->
function SetCookie(name, value, expires, path, domain, secure) {
var expDays = expires * 24 * 60 * 60 * 1000;
var expDate = new Date();
expDate.setTime(expDate.getTime() + expDays);
var expString = ((expires == null) ? "" : (";expires=" + expDate.toGMTString()))
var pathString = ((path == null) ? "" : (";path=" + path))
var domainString = ((domain == null) ? "" : (";domain=" + domain))
var secureString = ((secure == true) ? ";secure" : "")
document.cookie = name + "=" + escape(value) + expString + pathString + domainString + secureString;
}
<-------------------------读取Cookie------------------------------------>
function GetCookie(name) {
var result = "";
var myCookie = document.cookie + ";";
var searchName = name + "=";
var startOfCookie = myCookie.indexOf(searchName);
var endOfCookie;
if (startOfCookie != -1) {
startOfCookie += searchName.length;
endOfCookie = myCookie.indexOf(";", startOfCookie);
result = unescape(myCookie.substring(startOfCookie, endOfCookie));
}
return result;
}