Set cookies to expire in 1 hour in JavaScript
Advertisements
Learn how 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.
var now = new Date(); now.setTime(now.getTime() + 1 * 3600 * 1000); let cookieVal = escape(document.myform.customer.value) + ";" document.cookie="name=" + cookieVal; document.cookie = "expires=" + now.toUTCString() + ";" document.write ("Setting Cookies : " + "name=" + cookieVal );