A simple way to read and write cookies with JS

Source: Internet
Author: User

//function: Save cookies function parameter: Name,cookie name; value, values */function Se   Tcookie (name,value) {var days = 30*12;  The cookie will be saved for one year var exp = new Date ();  Get current Time Exp.settime (Exp.gettime () + days*24*60*60*1000);      Change to milliseconds Document.cookie = name + "=" + Escape (value) + "; expires=" + exp.togmtstring (); }/* Function: Get cookies function parameter: Name,cookie name */function GetCookie (name) {var arr = Document.cook Ie.match (New RegExp ("(^|)" +name+ "= ([^;]          *)(;|$)"));           if (arr! = null) {return unescape (arr[2]);          }else{return null; }}/* Function: Delete cookies function parameter: Name,cookie name */function Delcookie (name) {var exp =  New Date ();          Current Time Exp.settime (Exp.gettime ()-1);          var cval=getcookie (name);      if (cval!=null) document.cookie= name + "=" +cval+ "; expires=" +exp.togmtstring (); }  

  

A simple way to read and write cookies with JS

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.