15分钟后如何使Cookie过期 [英] how to make cookie expired after 15 minute
本文介绍了15分钟后如何使Cookie过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我有将cookie设置如下的js函数
hi all
i have js function which set cookie as below
function setCookie(name, value, days) {
if (days) {
var date = new Date();
date.setDate(date.getDate() + days);
var c_value = escape(value) + ((date == null) ? "" : "; expires=" + date.toUTCString());
}
else
var expires = ""; document.cookie = name + "=" + value + expires + "; path=/";
}
我现在想将Cookie设置为15分钟后过期
任何帮助
谢谢
i want now to set cookie to be expired after 15 minute
any help
Thanks
推荐答案
请遵循以下逻辑:
Follow this logic:
//original timestamp
var d1 = new Date (),
// new timestamp
d2 = new Date ( d1 );
d2.setMinutes ( d2.getMinutes() + 15 );
当然,您不需要两个对象,请根据需要使用.
Of course, you don''t need two objects, use this as needed.
这篇关于15分钟后如何使Cookie过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文