This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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?

 
It's a tiny ad. At least, that's what she said.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic