pillarOfLight
pillarOfLight

Reputation: 8982

setting both a persistent and nonpersistent cookie in javascript

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?

Upvotes: 0

Views: 2840

Answers (1)

Ramanlfc
Ramanlfc

Reputation: 8354

for session only cookie use :

document.cookie = "name=value;

for persistent cookie use :

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

Upvotes: 1

Related Questions