1

I would like to make an ongoing list of things and save them in a cookie so that when the do a lookup their last 20 items will show by default. I was just going to do a simple delimited variable and keep track and then save it to a cookie.

I was going to do something like:

document.cookie = "itemlist="+itemlist+"; expires=Thu, 18 Dec 2099 12:00:00 UTC; path=/";

Now, this is going to get sent with each request.

If I am using http://www.example.com/test.html, it is going to send.

Can I set it in test.html at:

document.cookie = "itemlist="+itemlist+"; expires=Thu, 18 Dec 2099 12:00:00 UTC; path=/save";

and still retrieve it with test.html even though the path is not save? If so, it would not send to the server when calling test.html, correct?

I have tried some of this, but with not decent results. Any suggestion would be appreciated.

AskYous
  • 4,332
  • 9
  • 46
  • 82
user999684
  • 705
  • 2
  • 10
  • 23
  • 2
    Use `localStorage` instead of a cookie. – Barmar Mar 05 '20 at 21:44
  • As @Barmar suggested, [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) is probably what you're looking for. Lets you save data to the user's computer so it's available, even if they leave and return to your website. – AskYous Mar 05 '20 at 21:45
  • Agreed. I have been doing this stuff for 15 years and did not know about that. Thanks! – user999684 Mar 06 '20 at 22:45

0 Answers0