jQuery cookie到期值

前端之家收集整理的这篇文章主要介绍了jQuery cookie到期值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在这里已经阅读了很多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在5分钟不活动后过期,并且我想通知用户他们的会话即将从Javascript到期.

解决方法

除非发生了某些变化,否则你无法从cookie中获取这个值,你可以设置它,但就是这样,当它到期时它就不会再出现在cookie集合中……但是你看不到它例如,它在5分钟后到期.

对于会话过期的最佳选择是使用setTimeout()并使用正确的延迟,例如,如果是5分钟,您可能需要在4分30秒时发出警报,如下所示:

setTimeout(function() {
  alert("Your session will expire in 30 seconds!");
},270000);  //4.5 * 60 * 1000
原文链接:https://www.f2er.com/jquery/180568.html

猜你在找的jQuery相关文章