我在这里已经阅读了很多jQuery cookie问题,并且知道有一个jQuery cookie插件(
jQuery cookie).没有做太多调查,问题是:有没有办法确定cookie的到期日期?
来自jquery.cookie doc:
- /**
- * Get the value of a cookie with the given name.
- *
- * @example $.cookie('the_cookie');
- * @desc Get the value of a cookie.
- *
- * @param String name The name of the cookie.
- * @return The value of the cookie.
- * @type String
- *
- * @name $.cookie
- * @cat Plugins/Cookie
- * @author Klaus Hartl/klaus.hartl@stilbuero.de
- */
这个插件似乎不能做到吗?
解决方法
除非发生了某些变化,否则你无法从cookie中获取这个值,你可以设置它,但就是这样,当它到期时它就不会再出现在cookie集合中……但是你看不到它例如,它在5分钟后到期.
对于会话过期的最佳选择是使用setTimeout()
并使用正确的延迟,例如,如果是5分钟,您可能需要在4分30秒时发出警报,如下所示:
- setTimeout(function() {
- alert("Your session will expire in 30 seconds!");
- },270000); //4.5 * 60 * 1000