获取Cookie
function GetCookie(cookieName) {
var cookieString = document.cookie;
var start = cookieString.indexOf(cookieName + '='); // 加上等号的原因是避免在某些 Cookie 的值里有 与 cookieName 一样的字符串。
if (start == -1) return null; // 找不到
start += cookieName.length + 1;
var end = cookieString.indexOf(';', start);
if (end == -1) return unescape(cookieString.substring(start));
return unescape(cookieString.substring(start, end));
}
设置cookie
function SetCookie(name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2 && argv[2] != null) ? argv[2].toGMTString() : null;
var path = (argc > 3 && argv[3] != null) ? argv[3] : '/';
var domain = (argc > 4 && argv[4] != null) ? argv[4] : null;
var secure = (argc > 5 && argv[5] != null) ? argv[5] : false;
var content = name + "=" + escape(value) + ";";
if (expires != null) { content += " expires=" + expires + ";"; }
if (path != null) { content += " path=" + path + ";"; }
if (domain != null) { content += " domain=" + domain + ";"; }
if (secure) { content += " secure;" }
document.cookie = content;
}