Cookie writing storage and reading key-Value Pair Functions

Source: Internet
Author: User
Function setcookie (name, value, expires, path, domain, secure) {var cookiename = encodeuricomponent (name) + '=' + encodeuricomponent (value); If (expires instanceof date) {cookiename + = '; expires =' + expires;} If (PATH) {cookiename + = '; Path =' + path;} If (domain) {cookiename + = '; domain = '+ domain;} If (secure) {cookiename + ='; secure ';} document. cookie = cookiename;} function getcookie (name) {VaR Cookiename = encodeuricomponent (name) + '='; var cookiestart = document. cookie. indexof (cookiename); var cookievalue = NULL; If (cookiestart>-1) {var cookieend = document. cookie. indexof (';', cookiestart); If (cookieend =-1) {cookieend = document. cookie. length;} cookievalue = document. cookie. substring (cookiestart + cookiename. length, cookieend);} return cookievalue;} console. log (getcookie ('email' ); Function setcookiedate (day) {var date = NULL; If (typeof day = 'number' & day> 0) {date = new date (); date. setdate (date. getdate () + day);} else {Throw new error ('the number of days you passed is invalid! Must be a number and greater than 0');} return date. togmtstring ();}
Setcookie ('user', 'happy ler', setcookiedate (7); setcookie ('url', 'yfdsae. com ', setcookiedate (7); setcookie ('email', '[email protected]', setcookiedate (7 ));

PS: Name = value; [expires = time; Path = path; domain = 'domain name'; secure = 'Secure encrypted link';]

Cookie writing storage and reading key-Value Pair Functions

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.