Js/jquery Get Cookie Value code
*/
function GetCookie (name, DC) {
var cname = name + "=";
if (Dc.length > 0) {
var begin = Dc.indexof (CNAME);
if (begin!=-1) {
Begin + = Cname.length;
End = Dc.indexof (",", begin);
if (end = = 1) {
end = Dc.length;
}
Return dc.substring (begin, end);
}
}
return null;
}
The jquery value is simpler because he has a self-contained function
Jquery.cookie = function (name, value, options) {
if (typeof value!= ' undefined ') {//name and value given, set cookie
options = Options | | {};
if (value = = null) {
Value = ';
Options = $.extend ({}, Options); Clone object since it ' s unexpected behavior if the expired property were changed
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;
}
};
How to use
$.cookie (' The_cookie ', ' The_value ', {expires:7, path: '/', Domain: ' 111cn.net ', secure:true});