

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 set cookies to expire in 30 minutes in JavaScript?
You can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date within the cookie. This can be done by setting the ‘expires’ attribute to a date and time.
Example
You can try to run the following example to set cookies to expire in 30 minutes
<html> <head> <script> <!-- function WriteCookie() { var now = new Date(); var minutes = 30; now.setTime(now.getTime() + (minutes * 60 * 1000)); cookievalue = escape(document.myform.customer.value) + ";" document.cookie="name=" + cookievalue; document.cookie = "expires=" + now.toUTCString() + ";" document.write ("Setting Cookies : " + "name=" + cookievalue ); } //--> </script> </head> <body> <form name="myform" action=""> Enter name: <input type="text" name="customer"/> <input type="button" value="Set Cookie" onclick="WriteCookie()"/> </form> </body> </html>
- Related Questions & Answers
- How to set cookies to expire in 1 hour in JavaScript?
- How to add 30 minutes to a JavaScript Date object?
- How to add 30 minutes to datetime in MySQL?
- How to set named cookies in JavaScript?
- How to set multiple cookies in JavaScript?
- How to set cookies expiry date in JavaScript?
- How to set cookies in ReactJS?
- How to use JavaScript to set cookies for homepage only?
- How to use JavaScript to set cookies for multiple pages?
- How to create cookies in JavaScript?
- How to delete cookies in JavaScript?
- How to use JavaScript to set cookies for a specific page only?
- How would I get a cron job to run every 30 minutes on Linux?
- How to store large data in JavaScript cookies?
- How to clear all cookies with JavaScript?
Advertisements