[thelist] JS cookie question (ignore previous)
Keith
cache at dowebscentral.com
Sat Jan 11 11:36:01 CST 2003
At 09:14 AM Friday 1/10/2003, Tom wrote:
>Now my test cookie is pid111=1. My problem is I get these results
>pulled:
>------------------------------------
>pid1= (1=1)
>pid10= (=1)
>pid11= (=1)
>pid111= (1)
>------------------------------------
>So it sees pid111 as a value for 1, 10, and 11 and 111 which is odd.
>It's actually pulling apart the cookie to give me the = sign as part
>of my response.
I think your problem is in using a substring search method for finding the
cookie name-value pair ("pid1" is also found in the strings "pid11" and
"pid111" etc.). If your users are using Version 3 or better browsers use
the array method for finding cookies instead. And instead of looking for
100 hypothetical pid+number cookies just look at cookies containing "pid".
The following
1) puts all cookies into the "cookies" array
2) loop through that array and parses a name=value string for any cookies
containing "pid"
4) alerts each name=value pair
getCookieData("pid")
function getCookieData(obj){
cookies=document.cookie.split(";");
for(i=0;i<cookies.length;++i){
if(cookies[i].indexOf(obj) != -1){
thisCookie=cookies[i].split("=")
alert(thisCookie[0]+"="+thisCookie[1])
}
}
}
Keith
====================
cache at dowebscentral.com
More information about the thelist
mailing list