jQuery cookie到期值 [英] jQuery cookie expiration value

查看:177
本文介绍了jQuery cookie到期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里阅读了许多jQuery Cookie问题,并且知道有一个jQuery Cookie插件( jQuery cookie )。没有多少调查,问题:有一种方法来确定cookie的过期日期?

I have read a lot of jQuery cookie questions on here and know there is a jQuery cookie plugin (jQuery cookie). Without doing much investigation, the question: is there a way to determine expiration date of cookie?

从jquery.cookie文档:

From the 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
*/

看起来这个插件可以吗?

Doesn't seem that this plugin can do it?

我想这样做的原因是我的cookie在5分钟不活动后过期,Id想通知用户他们的会话即将从Javascript过期。

The reason I want to do this is that my cookie expires after 5 minutes of inactivity and Id like to notify user that their session is about to expire from Javascript.

推荐答案

除非有任何变化,否则您无法从设置它,但它是,当它过期它只是不会显示在cookie集合中不再....但你不能看到它在5分钟内过期。例如。

Unless something has changed, you can't get this value from a cookie, you can set it but that's it, when it expires it just won't show up in the cookie collection anymore....but you can't see that it expires in 5 minutes for example.

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

Your best bet for something along the lines of session expiration is to use setTimeout() with the correct delay, for example if it's 5 minutes, you may want to alert at 4 min 30 seconds, like this:

setTimeout(function() {
  alert("Your session will expire in 30 seconds!");
}, 270000);  //4.5 * 60 * 1000

这篇关于jQuery cookie到期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆