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
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=/';
Share on FacebookShare on TwitterShare on LinkedInSend email
1 answer
x
x
2024 AnswerTabsTermsContact us