JS settings, delete, get user cookie information

Source: Internet
Author: User
Tags set cookie

JS settings, delete, get user cookie information

function GetCookie (name) {Obtaining cookie Information
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) {//Set cookie information
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 ': ');
}

Maybe you will ask how is a function that doesn't delete cookie information? Delete Cookies only set him to expire on OK.

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.