0

so I know that I can set cookie in javascript using document.cookie and according to this https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie

;expires=date-in-GMTString-format If not specified it will expire at the end of session

My question is, what if I want to set both a persistent cookie that expires at a specified date AND a session cookie that gets cleared the moment the session is closed?

What string should I set the document.cookie variable to in order to accomplish that?

1
  • Did you try to use multiple document.cookie= statements? Each statement should set another cookie - persistent or session based Commented Dec 3, 2015 at 17:53

1 Answer 1

1

for session only cookie use :

document.cookie = "name=value;

for persistent cookie use :

document.cookie = "name=value; expires=some GMT date string";

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.