views:

119

answers:

2

This is my asp code, can be the same done in Javascript?

HttpCookie cookie = this.Request.Cookies["Votes"];
if (cookie != null)
    if (cookie.Values.Get(id.ToString()) == "true")  return true;
return false;
+2  A: 

document.cookie gives you access to the cookies in JavaScript. You will need to do some parsing to do what you want to do.

phsiao
+2  A: 
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
}

These are all the parts of reading a cookie, you can use this snippet to achieve what you want.

Thanks,
Mahesh Velaga.

Mahesh Velaga
var the_cookie = unescape(the_cookie) just returns "Votes" without any values.
dani
dani
ans where do you use the_info parameter?
dani
Mahesh Velaga
is it possible to load only the "Votes" cookie? Because if i have more cookies on page, the_cookie = document.cookie; will return all of them concatenated in one string.
dani
try the_cookie = document.cookie["Votes"]; let me know .. :)
Mahesh Velaga
NO,doesn't work:undefinedi guess manual parsing is needed.
dani
the_cookie = document.cookie; the_cookie["Votes"] .. I think this should work other wise we have to split and get the values ..
Mahesh Velaga
this didn't work either
dani
sorry dani .. i am also a beginner software developer .. I shared to the extent that I know .. I will message you once I learn more about cookies .. good luck :)
Mahesh Velaga