A relatively easy to invoke a more functional cookie operation class with some simple application examples

Source: Internet
Author: User
Tags cookie names

A simpler cookie action class that can be easily invoked

With some simple application examples var axtic = axtic | | ... {} ;
Axtic. Cookies = ... {
/**//*
Function name: axtic. Cookie.get ([string name])
function function: Get cookie
Parameters: Name can be selected, the cookie names to be obtained
Description: Returns the value of the cookie name when all cookie,name are not empty when name is empty and returns undefined when there is no value
*/
Get:function (name) ... {
var CV = document.cookie.split (";"); /use "; The split cookie
var CVA = [], Cvat = [], Cvam = [], temp;
/**//* loop to get cookie name and value * *
for (i=0; i<cv.length; i++) ... {
temp = cv[i].split ("=");//split the name and value of the cookie with "="
if (Temp[0].indexof ("_divide_") > 0) ... {
Cvam[temp[0]] = temp[1];
}else ... {
if (Temp[0]!= "") cvat[i] = [temp[0], temp[1]];
}
}
for (i=0; i<cvat.length; i++) ... {
if (Cvat[i]) ... {
if (Cvat[i][1].substr (0,8)!= "^divide|") ... {
/**//* less than 4K cookie processing * *
Cva[cvat[i][0]] = unescape (cvat[i][1]);
}else ... {
/**//* greater than 4K cookie processing * *
var sta = cvat[i][1].indexof ("$"), tot = cvat[i][1].substring (8,sta);
Cva[cvat[i][0]] = cvat[i][1].substring (sta+1);
For (J=1 j<tot; j + +) ... {
Cva[cvat[i][0]] + + cvam[cvat[i][0]+ "_divide_" +j];
}
Cva[cvat[i][0]] = unescape (cva[cvat[i][0]);
}
}
}
if (name) return cva[name];//The cookie value of this name if there is a name
else return cva;//If no name is output with the name key, the value of the array
else return false;
},
/**//*
Function name: axtic. Cookie.set (string name, string value[, int expires[, string path[, String domain[, String secure]]]
function function: Depositing cookies
Argument: Name required, cookie name to be saved
Value required, the name of the cookie to be saved
Expires option, cookie expiration time, can be filled in seconds of the save time, can also fill in the date format (wdy, dd-mon-yyyy HH:MM:SS GMT) due time
Path option, cookie valid path on server side
Domain can be an option, the valid domain name for this cookie

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.