JavaScript Cookie Class (delete cookie, get, set cookie value

Source: Internet
Author: User
Tags set cookie setcookie

Function Issetcookie () {//web page effects Check cookie functions
    bannercenter = Web effects getcookie (' Bannercenter ');
    if (bannercenter!=null && bannercenter!= "") {
         return true;
   } else {
        setcookie (' Bannercenter ', 1,3600*24);
   }
}


//===============================================
function Jsgetcookie (name) {//Get the original value of the cookie
var Cookstringarray = Window.document.cookie.split (";");
for (var i=0; i<cookstringarray.length;i++) {
var cookieinfo = cookstringarray[i].split ("=");
if (name = = Cookieinfo[0]) {
Return unescape (cookieinfo[1]);
}
}
return null;
}

function Setcookie (name, value) {//Set cookie value
var expdate = new Date ();
var argv = setcookie.arguments;
var argc = setcookie.arguments.length;
var expires = (argc > 2)? ARGV[2]: null;
var path = (argc > 3)? ARGV[3]: null;
var domain = (argc > 4)? ARGV[4]: null;
var secure = (argc > 5)? ARGV[5]: false;
if (expires!=null) Expdate.settime (Expdate.gettime () + (expires * 1000));
Document.cookie = name + "=" + Escape (value) + ((expires = null)? "" : ("; Expires= "+ expdate.togmtstring ()))
+ ((path = null)? "" : ("; Path= "+ path") + ((domain = null)? "" : ("; domain= "+ domain)"
+ (Secure = = True)? "; Secure ":" ");
}
//=============================================
function Delcookie (name) {//delete cookie
var exp = new Date ();
Exp.settime (Exp.gettime ()-1);
var cval = GetCookie (name);
Document.cookie = name + "=" + Cval + "; Expires= "+ exp.togmtstring ();

}

Related Article

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.