var cookieName = "cookie name";
var cookieValue = null;//Return the value of the cookie
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');//will get Cut all cookies into arrays
for (var i = 0; i < cookies.length; i ) {
var cookie = cookies[i];//Get the cookies array of a certain subscript
if ( cookie.substring(0, cookieName.length 2).trim() == cookieName.trim() "=") {//If the cookie exists, take out the cookie value
cookieValue = cookie.substring( cookieName.length 2, cookie.length);
break
}
}
}
if (cookieValue != "" && cookieValue != null) {//If the specified cookie exists Value
alert(cookieValue);
} else {//If the cookie value is empty
alert("not cookie!!!");
}
//Remove spaces
String.prototype.trim = function () {
return this.replace(new RegExp("(^[\s]*)|( [\s]*$)", "g"), "");
}
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