jquery Action Cookie

Source: Internet
Author: User
Tags set cookie

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.