{
setCookie: function(sName, sValue, oExpires, sPath, sDomain, bSecure) {
var sCookie = sName + "=" + encodeURIComponent(sValue); // 名称和值
if (oExpires) {
var data = new Date();
data.setTime(data.getTime() + oExpires * 60 * 60 * 1000);
sCookie += "; expires=" + data.toUTCString(); // 过期时间
}
if (sPath) {
sCookie += "; path=" + sPath; // 访问路径
}
if (sDomain) {
sCookie += "; domain=" + sDomain; // 访问路径
}
if (bSecure) {
sCookie += "; secure"; // 安全性
}
document.cookie = sCookie;
},
getCookie: function(sName) {
var sRE = '(?:; )?' + sName + '=([^;]*)';
var oRE = new RegExp(sRE);
if (oRE.test(document.cookie)) {
return decodeURIComponent(RegExp['$1']);
} else {
return null;
};
},
removeCookie: function(sName, sPath, sDomain) {
this.setCookie(sName, '', new Date(0), sPath, sDomain);
},
clearAllCookie: function() {
var cookies = document.cookie.split(';');
var len = cookie.length;
for(var i = 0; i < len; i++){
var cookie = cookie[i];
var eqPos = cookie.indexof('=');
var name = eqPos > -1 ? cookie.substr(0, eqPos):cookie;
name = name.replace(/^s*|s*$/, '');
this.removeCookie(name);
}
}
}