โค้ด: เลือกทั้งหมด
DP_Cookies = new Object();
DP_Cookies.enabled = function() {
return navigator.cookieEnabled
};
DP_Cookies.set = function(Name, Value, Timespan, TimespanUnit, Domain, Path, Secure) {
// Set the Name
Name = Name.replace(/^\s*|\s*$/g,"");
// Set the Value
if ( Value ) { Value = escape(Value) } else { Value="" };
// Set the Expires Value
if ( typeof Timespan == "number" ) {
var CurDate = new Date();
switch (TimespanUnit) {
case "days":
Timespan = Timespan * 24 * 60 * 60 * 1000;
break;
case "hours":
Timespan = Timespan * 60 * 60 * 1000;
break;
case "minutes":
Timespan = Timespan * 60 * 1000;
break;
case "seconds":
Timespan = Timespan * 1000;
break;
default:
Timespan = Timespan * 24 * 60 * 60 * 1000;
break;
};
CurDate.setTime(CurDate.getTime() + Timespan);
var Expires = "; expires=" + CurDate.toGMTString();
} else {
var Expires = "";
};
// Set the Path value
if ( Path ) { Path = "; path=" + Path } else { Path = "" };
// Set the Domain value
if ( Domain ) { Domain = "; domain=" + Domain } else { Domain = "" };
// Set the Secure value
if ( Secure ) { Secure = "; secure" } else { Secure = "" };
var CookieValue = Name + "=" + Value + Expires + Path + Domain + Secure;
// Write the Cookie
document.cookie = CookieValue;
// Return the cookie
return CookieValue;
};
DP_Cookies.erase = function(Name) {
// Delete the cookie by calling "set" with a negative expiry value
this.set(Name.replace(/^\s*|\s*$/g,""), "", -1);
// Return "true"
return true;
};
DP_Cookies.eraseAll = function() {
var Cookies = document.cookie.split(";");
for ( var Cnt=0; Cnt < Cookies.length; Cnt++ ) {
var CurCookie = Cookies[Cnt].split("=");
if ( CurCookie[0] ) {
this.set(CurCookie[0].replace(/^\s*|\s*$/g,""), "", -1);
};
};
// Return "true"
return true;
};
DP_Cookies.get = function(Name) {
// Set the Name
Name = Name.replace(/^\s*|\s*$/g,"");
var Cookies = document.cookie.split(";");
for ( var Cnt=0; Cnt < Cookies.length; Cnt++ ) {
var CurCookie = Cookies[Cnt].split("=");
if ( CurCookie[0].replace(/^\s*|\s*$/g,"") == Name ) {
if ( CurCookie[1] ) {
return CurCookie[1];
} else {
return "";
};
};
};
return null;
};
DP_Cookies.getAll = function() {
var AllCookies = new Object;
var Cookies = document.cookie.split(";");
for ( var Cnt=0; Cnt < Cookies.length; Cnt++ ) {
var CurCookie = Cookies[Cnt].split("=");
if ( CurCookie[0] ) {
if ( CurCookie[1] ) {
AllCookies[CurCookie[0].replace(/^\s*|\s*$/g,"")] = CurCookie[1];
} else {
AllCookies[CurCookie[0].replace(/^\s*|\s*$/g,"")] = "";
};
};
};
return AllCookies;
};
โค้ด: เลือกทั้งหมด
DP_Cookies.eraseAll();