Js gets the specific implementation of the specified cookie
- 2020-03-30 02:05:15
- OfStack
var cookieName = "cookie The name ";
var cookieValue = null;//Returns the value of the cookie
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');//Cut all the obtained cookies into an array
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];//Gets an array of cookies for a certain index
if (cookie.substring(0, cookieName.length + 2).trim() == cookieName.trim() + "=") {//If the cookie exists, the value of the cookie is pulled out
cookieValue = cookie.substring(cookieName.length + 2, cookie.length);
break
}
}
}
if (cookieValue != "" && cookieValue != null) {//If the specified cookie value exists
alert(cookieValue);
} else {<span style="font-family: Arial, Helvetica, sans-serif;">//If the value of the cookie is null </ span>
alert("not cookie!!!");
}
//Remove the blank space
String.prototype.trim = function () {
return this.replace(new RegExp("(^[\s]*)|([\s]*$)", "g"), "");
}