How to set session temporary cookies with Javascript ?

Until now I used only persistent cookies. Now I need to create a session cookie that will expire when the browser closes. Could you please give me suggestion how to do it ?
give a positive ratinggive a negative rating
22 Jun 2019 at 07:17 PM

To create a session cookies, you have to use a similar code like in case of persistent cookies. Only difference is, that you have to not include the expiration date.

Example of persistent cookie code:

var date = new Date();
var expiry = '; expires=' + date.toUTCString();
document.cookie = 'abc=123'+expiry+'; path=/';

Example of session cookie code:

document.cookie = 'abc=123; path=/';
give a positive ratinggive a negative rating
24 Jun 2019 at 07:23 PM
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook
2022 AnswerTabsTermsContact us