Js cookie-related operation functions
// Check whether the browser supports cookies
Function checkCookie (){
// Determine whether the cookie is enabled
Var cookieEnabled = (navigator. cookieEnabled )? True: false;
// If the browser is not ie4 + or ns6 +
If (typeof navigator. cookieEnabled = "undefined "&&! CookieEnabled ){
Document. cookie = "testcookie ";
CookieEnabled = (document. cookie = "testcookie ")? True: falsedocument. cookie = "";
}
// If not enabled
If (cookieEnabled ){
Return true;
} Else {
Return false;
}
}
// Add Cookie
Function addCookie (name, value, expireHours ){
Var cookieString = name + "=" + escape (value );
// Determine whether to set the expiration time
If (expireHours> 0 ){
Var date = new Date ();
Date. setTime (date. getTime + expireHours * 3600*1000 );
CookieString = cookieString + "; expire =" + date. toGMTString ();
}
Document. cookie = cookieString;
}
// Obtain the Cookie value
Function getCookie (name ){
Var strCookie = document. cookie;
Var arrCookie = strCookie. split (";");
For (var I = 0; I <arrCookie. length; I ++ ){
Var arr = arrCookie [I]. split ("= ");
If (arr [0] = name ){
Return unescape (arr [1]);
}
}
Return false;
}
// Delete the Cookie
Function deleteCookie (name ){
Var date = new Date ();
Date. setTime (date. getTime ()-10000 );
Document. cookie = name + "=; expire =" + date. toGMTString ();
}