Jquery operation cookie

Source: Internet
Author: User
Tags set cookie

note the Cookie Path setting. If path: '/' is not set, the path is automatically set according to the directory. For example: http://www.xxx.com/user/, pathwill be set to '/user']

$. Extend ({/** 1. set the cookie value and set the value of the name variable to value example $. cookie ('name', 'value'); 2. create a cookie, including the Domain Name of the validity period and other example $. cookie ('name', 'value', {expires: 7, path: '/', domain: 'jquery. com ', secure: true}); 3. create cookieexample $. cookie ('name', 'value'); 4. delete A cookieexample $. cookie ('name', null); 5. get a cookie (name) value to myvarvar account = $. cookie ('name'); **/cookiehelper: function (name, value, options) {If (typeo F 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 {d Ate = options. expires;} expires = '; expires =' + date. toutcstring (); // 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 ;}}});

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.