1

ok, so I guess I'm missing something very simple here, but can't manage to store more than one cookie with this function:

function safe_item(name) {
document.cookie = 'item name:' + name;
}

It works exactly as expected, but when a new cookie is created, the previous one just disappears :/

1
  • You have to append all the cookies into a single string. Be careful to not slice out parts not related to your own app. Eg, you'll find a google analytics chunk in alot of cookie strings as well that you don't want to remove. Commented Jun 12, 2019 at 9:39

1 Answer 1

2

That's because document.cookie only accepts a single string as value;

So, instead of document.cookie = 'item name:' + name;, do this document.cookie += 'item name:' + name;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.