开发者

Change this function to make the cookie expire to 30 seconds

开发者 https://www.devze.com 2023-04-07 13:48 出处:网络
How can I change this function to expire instead of days in 30 seconds?, I have no idea about this.. and its from Telerik

How can I change this function to expire instead of days in 30 seconds?, I have no idea about this.. and its from Telerik

function setCookie(c_name,value,expi开发者_高级运维redays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
} 


You could use the valueOf function:

var numberOfSeconds = 30;
var exdate = new Date(new Date().valueOf() + 1000 * numberOfSeconds);


Instead of .getDate() and .setDate() (which get and set the day-of-the-month), use getSeconds:

exdate = new Date(exdate.setSeconds(exdate.getSeconds()+30));
0

精彩评论

暂无评论...
验证码 换一张
取 消