Code
Jquery.cookie =function(name, value, options) {if(typeofValue! = ' undefined ') {//name and value given, set cookieoptions = Options | | {}; if(Value = = =NULL) {Value= ' '; Options.expires=-1; } varexpires = ' '; if(Options.expires && (typeofOptions.expires = = ' Number ' | |options.expires.toUTCString)) {vardate; if(typeofOptions.expires = = ' Number ') {Date=NewDate (); 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 } varPath = Options.path? ‘; Path= ' + options.path: '; varDomain = Options.domain? ‘; Domain= ' + options.domain: '; varSecure = options.secure? ‘; Secure ': '; Document.cookie= [Name, ' = ', encodeURIComponent (value), expires, path, domain, Secure].join ("); } Else{//Only name given, get cookie varCookievalue =NULL; if(Document.cookie && Document.cookie! = ") { varcookies = Document.cookie.split ('; ')); for(vari = 0; i < cookies.length; i++) { varCookie =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; } } } returnCookievalue; }};functionGetCookie (name) {varCookie_start =document.cookie.indexOf (name);varCookie_end = Document.cookie.indexOf (";", Cookie_start);returnCookie_start = =-1? ": Unescape (document.cookie.substring (Cookie_start + name.length + 1, (Cookie_end > Cookie_start?)cookie_end:document.cookie.length))) ;}functionSetcookie (CookieName, cookievalue, seconds, path, domain, secure) {varexpires =NewDate (); Expires.settime (Expires.gettime ()+seconds); Document.cookie= Escape (cookiename) + ' = ' +Escape (Cookievalue)+ (expires?) ‘; Expires= ' + expires.togmtstring (): ') + (path?) ‘; Path= ' + path: '/') + (domain? ‘; Domain= ' + domain: ') + (secure?) ‘; Secure ': ');}
Provides methods to manipulate cookies:
// Get Cookies // Set Cookies // set Cookies with time 7 days // delete null// Delete Cookie7, Path: '/', Domain: ' jquery.com ', secure:true});
jquery Action Cookie