Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loop through cookies and get value for a particular cookie name.

 
forums UseR
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello fellow Ranchers,

Can anybody point me to code/resources on how to loop through cookies to get hold of the value for a particular cookie.

Thanks

Srinivas
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start here: JavaScript getCookie

Eric
 
forums UseR
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:I would start here: JavaScript getCookie

Eric


Hi Eric,

I followed your google search and found this resource



The above code seems flawed, since it won't search my cookie that I have created earlier. As a result, it is freshly creating another cookie with the same name.

Something strange is happening, the new cookie is getting created at a different path than the earlier one!

When I check details about document.cookie , after I have already created one with a name 'selection', I don't see selection anywhere in the cookie (because it is searching from a different path!)

Is it possible to loop through 2 paths, and get all the cookies. Here are the 2 paths




 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code is not creating a different cookie. It is taking the cookie and splitting it up and storing it in an object.

How are you creating the cookie? When the cookie is created are you setting the domain?

Eric
 
forums UseR
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:
How are you creating the cookie? When the cookie is created are you setting the domain?
Eric


Here is my setCookie code:



The above 'alert' won't print the cookie that I created earlier with the same name (as it was already created at a different path)
Is this because I am not considering the path ? The domain is same for the 2 cookies, only the path is different...

Thanks

Srinivas
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is the cookie being created?

Eric
 
forums UseR
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i create cookie, its getting saved at a certain location. I click a button and go to a different tab ( a different page). I still see the cookie.

When I click back to original screen, the browser is not able to retrieve the cookie that I created earlier. And my code will create a new cookie if one doesn't exist already. This new cookie is getting created at a different location. Now I see the same cookie name at 2 different paths.

How to fix this?

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic