var CookieHelper = {
getCookieVal : function(offset) {//获得Cookie解码后的值
var endstr = document.cookie.indexOf (";", offset);
if(-1 == endstr) {
endstr = document.cookie.length;
}
return (unescape(document.cookie.substring(offset, endstr)));
},
setCookie : function(name, value) { //设定Cookie值
var expdate = new Date();
var argv = arguments;
var argc = arguments.length;
var expires = ((argc > 2) ? argv[2] : null);
var path = ((argc > 3) ? argv[3] : null);
var domain = ((argc > 4) ? argv[4] : null);
var secure = ((argc > 5) ? argv[5] : false);
if(null != expires) {
expdate.setTime(expdate.getTime() + (expires * 1000));
}
document.cookie = name + "=" + escape (value)
+ ((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+ ((path == null) ? "" : ("; path=" + path))
+ ((domain == null) ? "" : ("; domain=" + domain))
+ ((secure == true) ? "; secure" : "");
},
delCookie : function(name) { //删除Cookie
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = this.getCookie(name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
},
getCookie : function(name) { //获得Cookie的原始值
var arg = name + "=";
var nameLen = arg.length;
var cookieLen = document.cookie.length;
var step = 0;
while (step < cookieLen){
var end = step + nameLen;
if (document.cookie.substring(step, end) == arg) {
return this.getCookieVal(end);
}
step = document.cookie.indexOf(" ", step) + 1;
if (0 == step) break;
}
return (null);
}
};