简体   繁体   English

jQuery cookie过期检测

[英]JQuery cookie expiration detection

I am using JQuery $.cookie to save some data in my app and was wondering if there is a way to detect if the $.cookie has already expired or not? 我正在使用JQuery $ .cookie将一些数据保存在我的应用程序中,并且想知道是否存在一种方法来检测$ .cookie是否已过期?

I know I can check the content by reading the cookie, but how can I know if the cookie already expired or not? 我知道我可以通过阅读cookie来检查内容,但是如何知道cookie是否已过期? Thanks 谢谢

If the cookie has already expired, $.cookie('cookieName') will return undefined: 如果cookie已经过期,则$.cookie('cookieName')将返回undefined:

if(typeof $.cookie('cookieName') === 'undefined'){

    // 'cookieName' expired (or never existed)
}

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM