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 ?
0
give a positive ratinggive a negative rating
22 Jun 2019 at 07:17 PM
Hi,

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();
date.setTime(date.getTime()+(3600*1000));
var expiry = '; expires=' + date.toUTCString();
document.cookie = 'abc=123'+expiry+'; path=/';


Example of session cookie code:

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