// Cookie管理
function CookieManage() {
// 填充数据到Cookie
this.setCookie = function(name, value, days) {
var cycleTime = 30 * 60 * 1000;
if (days)
cycleTime = days * 24 * cycleTime;
var exp = new Date();
// 设置生命周期
exp.setTime(exp.getTime() + cycleTime);
document.cookie = name + "=" + escape(value) + ";expires="
+ exp.toGMTString();
}
// 获取Cookie中的数据
this.getCookie = function(name) {
var arr = document.cookie.match(new RegExp("(^| )" + name
+ "=([^;]*)(;|$)"));
if (arr != null)
return unescape(arr[2]);
return null;
}
// 清除Cookie中的数据
this.delCookie = function(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = this.getCookie(name);
if (cval != null)
document.cookie = name + "=" + cval + ";expires="
+ exp.toGMTString();
}
// 清除所有Cookie
this.clearCookies = function() {
if (confirm('你确定要清空所有Cookie吗?')) {
var temp = document.cookie.split(";");
var ts;
for ( var i = 0;; i++) {
if (!temp[i])
break;
ts = temp[i].split("=")[0];
delCookie(ts);
}
}
}
}