- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
- Related Articles
- How to create cookies in JavaScript?
- How to use JavaScript to set cookies for homepage only?
- How to use JavaScript to set cookies for a specific page only?
- How to create domain-based cookies using JavaScript?
- Difference between Local Storage, Session Storage, and Cookies in JavaScript
- How to clear all cookies with JavaScript?
- What is the difference between session and cookies?
- How to get the cookies associated with a document in JavaScript?
- How to create a new object with only a subset of properties using vanilla Javascript
- How can I delete all cookies with JavaScript?
- How to delete cookies in JavaScript?
- How to show name/value pairs of cookies in a document with JavaScript?
- How to set named cookies in JavaScript?
- How to set multiple cookies in JavaScript?
- How to read cookies with JSP?

Advertisements