This article mainly introduces how to use the Cookie Access value for js files. For more information, see
The Code is as follows:
/*
Cookie Tool
Usage:
// Save Value
Var value = "7 days ";
Tools. cookie ("day", value, {expires: 7}); // Save the string "7 days" with the key "day" to the cookie for 5 days
// Value
Var v = tools. cookie ("day"); // use the "day" key to retrieve the value from the cookie.
*/
Tools. cookie = function (name, value, options ){
If (typeof value! = 'Undefined') {// name and value given, set cookie
Options = options | {};
If (value = null ){
Value = '';
Options. expires =-1;
}
Var expires = '';
If (options. expires
& (Typeof options. expires = 'number' | options. expires. toGMTString )){
Var date;
If (typeof options. expires = 'number '){
Date = new Date ();
Date. setTime (date. getTime ()
+ (Options. expires * 24x60*60*1000 ));
} Else {
Date = options. expires;
}
Expires = '; expires =' + date. toGMTString (); // use expires
// Attribute,
// Max-age is not
// Supported by IE
}
Var path = options. path? '; Path =' + options. path :'';
Var domain = options. domain? '; Domain =' + options. domain :'';
Var secure = options. secure? '; Secure ':'';
Document. cookie = [name, '=', encodeURIComponent (value), expires,
Path, domain, secure]. join ('');
} Else {// only name given, get cookie
Var cookieValue = null;
If (document. cookie & document. cookie! = ''){
Var cookies = document. cookie. split (';');
For (var I = 0; I <cookies. length; I ++ ){
Var cookie = jQuery. trim (cookies [I]);
// Does this cookie string begin with the name we want?
If (cookie. substring (0, name. length + 1) = (name + '= ')){
CookieValue = decodeURIComponent (cookie
. Substring (name. length + 1 ));
Break;
}
}
}
Return cookieValue;
}
};