• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would start here: JavaScript getCookie

Eric
 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is the cookie being created?

Eric
 
forums UseR
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic