Could someone update the following code to make the cookie expire in 30 seconds.
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
To easily delete any cookie, simply set its expiration date as the epoch timestamp: document. cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"; document.
Nope. That can't be done. The best 'way' of doing that is just making the expiration date be like 2100.
COOKIES, COMMERCIALLY PACKAGED - UNOPENED Properly stored, a package of unopened cookies will generally stay at best quality for about 6 to 9 months.
Sets the maximum age of the cookie in seconds. This will result in a cookie1 to expire in 20 seconds.
function createCookie(name, value) {
var date = new Date();
date.setTime(date.getTime()+(30*1000));
var expires = "; expires="+date.toGMTString();
document.cookie = name+"="+value+expires+"; path=/";
}
You can specify the maximum age in seconds when setting a cookie:
function setCookie(name, value, maxAgeSeconds) {
var maxAgeSegment = "; max-age=" + maxAgeSeconds;
document.cookie = encodeURI(name) + "=" + encodeURI(value) + maxAgeSegment;
}
Usage:
setCookie("username", "blaise", 30);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With