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: 16-Jun-2020

796 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements