在javascript中读取cookie

dan*_*ani 1 javascript asp.net

这是我的asp代码,可以在Javascript中完成吗?

HttpCookie cookie = this.Request.Cookies["Votes"];
if (cookie != null)
    if (cookie.Values.Get(id.ToString()) == "true")  return true;
return false;
Run Code Online (Sandbox Code Playgroud)

Mah*_*aga 6

function readTheCookie(the_info)
{
// load the cookie into a variable and unescape it

 var the_cookie = document.cookie;
 var the_cookie = unescape(the_cookie);

// separate the values from the cookie name

 var broken_cookie = the_cookie.split("some parameter"); // parameter depends on how the cookie is stored
 var the_values = broken_cookie["some index"]; // index of the value that you want
}
Run Code Online (Sandbox Code Playgroud)

这些都是阅读cookie的所有部分,您可以使用此片段来实现您想要的.