Home >Web Front-end >JS Tutorial >Javascript reads background cookie code_javascript skills

Javascript reads background cookie code_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:01:13908browse

The following is the regular method I use to get cookies, including single value and multi-value:

Copy code The code is as follows:

/************************************************
Parameter description:
sMainName Cookie name
sSubName Cookie subkey name, leave blank to indicate single value Cookie
************************ ****************************/
function GetCookie(sMainName, sSubName)
{
var re = new RegExp(sMainName (sSubName ? "=" sSubName : "") "= (.*?);", "i");
return re.test(unescape(document.cookie)) ? RegExp["$1"] : "";
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn