Http://www.cnblogs.com/qiantuwuliang/archive/2009/07/19/1526663.html
The JQuery cookie is a good cookie plugin, presumably using the following method
Example $.cookie (' name ', ' value ');
Set the value of the cookie to set the value of the name variable to
Example $.cookie (' name ', ' value ', {expires:7, path: '/', Domain: ' jquery.com ', secure:true});
Create a new cookie including the validity path domain name, etc.
Example $.cookie (' name ', ' value ');
New Cookie
Example $.cookie (' name ', null);
Delete a cookie
var account= $.cookie (' name ');
Take a cookie (name) value to MyVar
The code is as follows
Jquery.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.toUTCString)) {
var date;
if (typeof options.expires = = ' number ') {
Date = new Date ();
Date.settime (Date.gettime () + (Options.expires * 24 * 60 * 60 * 1000));
} else {
date = Options.expires;
}
expires = '; Expires= ' + date.toutcstring (); Use expires attribute, Max-age isn't 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;
}
};
And then see how the cookie is manipulated in the next discuz!.
As below, it is found that a traversal is missing; processing of segmented arrays
function GetCookie (name) {
var cookie_start = document.cookie.indexOf (name);
var cookie_end = document.cookie.indexOf (";", Cookie_start);
return Cookie_start = =-1? ": Unescape (document.cookie.substring (Cookie_start + name.length + 1, (Cookie_end > Cookie_start? cookie_end:docum (ent.cookie.length)));
}
function Setcookie (cookiename, cookievalue, seconds, path, domain, secure) {
var expires = new Date ();
Expires.settime (Expires.gettime () + seconds);
Document.cookie = Escape (cookiename) + ' = ' + Escape (cookievalue)
+ (expires?) ‘; Expires= ' + expires.togmtstring (): ')
+ (path?) ‘; Path= ' + path: '/')
+ (domain? ‘; Domain= ' + domain: ')
+ (secure?) ‘; Secure ': ');
}