使Cookie在15分钟内过期的功能

时间:2018-10-28 19:51:39

标签: javascript cookies

我正在尝试编写一个函数来使Cookie在15分钟内过期。我写的正确吗?谢谢。

setCookieExpireIn("cookieName", "value", 15);

function setCookieExpireIn(cookieName, value, expireIn) {
var now = new Date();
var minutes = expireIn;
now.setTime(now.getTime() + (minutes * 60 * 1000));
document.cookie = cookieName + "=" + value + "; expires = " + now.toUTCString() + ";";
} //end of function addToCookieAndExpireIn(cookieName, value, expireIn)

0 个答案:

没有答案