jQuery cookie持久化 [英] jQuery cookie persistence
问题描述
我使用此jquery插件成功地将Cookie添加到网站上的jQuery Ajax应用程序。
I am using this jquery plugin to successfully add cookies to a jQuery Ajax application on a website.
但是,我的很短的问题是,如何设置cookie无限期存在?
But, my very short question is, how can I set the cookie to exist indefinately?
我试图记住用户的偏好设置,将它们长期存储在包含每个用户唯一的数据数组的Cookie中。
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.
谢谢。
推荐答案
您无法将Cookie设置为无限期。
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.
您可以设置一个过期日期,并且过期日期必须有一个特定的值。该cookie存活一年,例如:
You can make the cookie live for a year, for example:
$.cookie('the_cookie', 'the_value', { expires: 365 });
您也可以使用 Date
到期日期,但您应该保留日期在2038年的这一侧,因为一些系统不支持之后的日期。
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.
这篇关于jQuery cookie持久化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!