I am using this jquery plugin to successfully add cookies to a jQuery Ajax application on a website.
But, my very short question is, how can I set the cookie to exist indefinately?
I am trying to remember users preferences settings by storing them long term in a cookie containing an array of data unique to each user.
Thank you.
You can't set a cookie to exist indefinitely. You make a cookie persistent by setting an expiration date on it, and as the expiration date has to have a specific value, that's when the cookie will expire.
You can make the cookie live for a year, for example:
$.cookie('the_cookie', 'the_value', { expires: 365 });
You can also use a Date
object for the expiration date, but you should keep the date on this side of year 2038, as some systems doesn't support dates after that yet.
You can't set a cookie to "never" expire, but you can do just as good.
Usually I prefer to set cookies for 30 days, and renew them whenever the user accesses a page. As long as the user doesn't leave for a month, the cookie is permanent.
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