javascript设置cookie到期时间 [英] javascript set cookie with expire time
本文介绍了javascript设置cookie到期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过Javascript设置cookie,它工作正常,但它没有采取到期时间,我给。它不断接受会话的价值,不管我给了什么,下面是我从这里
I am setting a cookie by Javascript and it is working fine but it is not taking the expire time I am giving. It keeps on taking session value regardless of what I give, below is the code which I took from here
var now = new Date();
var time = now.getTime();
var expireTime = time + 1000*60;
now.setTime(expireTime);
var tempExp = 'Wed, 31 Oct 2012 08:50:17 GMT';
document.cookie = aaa+'='+sStr+';expires='+now.toGMTString()+';path=/';
我试图给硬编码的值,但仍然显示在chrome dev工具中作为会话过期
I tried giving hard-coded value but still it is showing expire as session in chrome dev tool
var tempExp = 'Wed, 31 Oct 2012 08:50:17 GMT';
document.cookie = aaa+'='+sStr+';expires='+tempExp+';path=/';
任何想法我做错了什么?
Any idea what I am doing wrong?
推荐答案
我认为它的确定。我已将时间设置为1000 * 36000。
I think its ok. I've set time to 1000*36000.
function display() {
var now = new Date();
var time = now.getTime();
var expireTime = time + 1000*36000;
now.setTime(expireTime);
var tempExp = 'Wed, 31 Oct 2012 08:50:17 GMT';
document.cookie = 'cookie=ok;expires='+now.toGMTString()+';path=/';
//console.log(document.cookie);
}
这篇关于javascript设置cookie到期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文