How to create a session only cookies with JavaScript?



To create a session only cookie, you need to set the expiration date of the cookie to be some years ahead. You need to set the expire attribute βˆ’

current time + 5 years

The expire attribute shows the date the cookie will expire. If this is blank, the cookie will expire when the visitor quits the browser.

Note βˆ’ Do not consider removing the expire value to create a session only cookie. This won’t work. Set the expire attribute to the future date.

Updated on: 2020-06-16T12:15:34+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements