复制代码 代码如下:
function getcookieval (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) {
endstr = document.cookie.length;
}
return unescape(document.cookie.substring(offset, endstr));
}
复制代码 代码如下:
function FixcookieDate (date) {
var base = new Date(0);
var skew = base.getTime(); // dawn of (Unix) time - should be 0
if (skew > 0) { // except on the Mac - ahead of its time
date.setTime(date.getTime() - skew);
}
}
复制代码 代码如下:
function Getcookie (name) {
var temp = name + "=";
var tempLen = temp.length;
var cookieLen = document.cookie.length;
var i = 0;
while (i < cookieLen) {
var j = i + tempLen;
if (document.cookie.substring(i, j) == temp) {
return getcookieval(j);
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
复制代码 代码如下:
function Setcookie (name,value,expiresDate,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expiresDate) ? "; expires=" + expiresDate.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
复制代码 代码如下:
function Deletecookie (name,path,domain) {
if (Getcookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
// Calling examples:
// var expdate = new Date ();
// FixcookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
// expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
// Setcookie ("ccpath", "http://www.dupcit.com/articles/", expdate);
// Setcookie ("ccname", "WebWoman", expdate);
// Setcookie ("tempvar", "This is a temporary cookie.");
// Setcookie ("ubiquitous", "This cookie will work anywhere in this domain",null,"/");
// Setcookie ("paranoid", "This cookie requires secure communications",expdate,"/",null,true);
// Setcookie ("goner", "This cookie must die!");
// document.write (document.cookie + "
");
// Deletecookie ("goner");
// document.write (document.cookie + "
");
// document.write ("ccpath = " + Getcookie("ccpath") + "
");
// document.write ("ccname = " + Getcookie("ccname") + "
");
// document.write ("tempvar = " + Getcookie("tempvar") + "
");