0
我試圖爲我的網站設置一個cookie,將在3分鐘內過期,但沒有運氣,所以我找到了工作30天內到期的代碼完美,但我很難將其設置3分鐘。試圖在3分鐘內過期的餅乾
/**
* JS script with cookie integration for redirecting visitors to a splash page. jQuery free.
*
* @author Tyler Pearson
* @version 1.0
*/
var NMC = NMC || {};
NMC.Splash = (function() {
"use strict";
var daysBeforeCookieExpires = 30, //Need to change it for 3 min!!!
createCookie = function(name, value, expires, path, domain) {
var cookie = name + "=" + escape(value) + ";";
if (expires) {
if (expires instanceof Date) {
if (isNaN(expires.getTime())) {
expires = new Date();
}
} else {
expires = new Date(new Date().getTime() + parseInt(expires, 10) * 1000 * 60 * 60 * 24);
}
cookie += "expires=" + expires.toGMTString() + ";";
}
if (path) {
cookie += "path=" + path + ";";
}
if (domain) {
cookie += "domain=" + domain + ";";
}
document.cookie = cookie;
},
getCookie = function(name) {
var regexp = new RegExp("(?:^" + name + "|;\\s*" + name + ")=(.*?)(?:;|$)", "g"),
result = regexp.exec(document.cookie);
return (result === null) ? null : result[1];
},
readCookie = function(name) {
var nameEQ = name + "=",
ca = document.cookie.split(';'),
i,
c;
for (i = 0; i < ca.length; i += 1) {
c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) === 0) {
return c.substring(nameEQ.length, c.length);
}
}
return null;
};
return {
baseSetup: function(cookieName, splashURL) {
if (!(getCookie(cookieName))) {
createCookie("_splash-entrance", window.location.pathname, daysBeforeCookieExpires);
window.location = splashURL;
}
},
splashSetup: function(cookieName, expiresInDays) {
if (expiresInDays) {
daysBeforeCookieExpires = expiresInDays;
}
var link = document.getElementById('splash-continue');
createCookie(cookieName, true, daysBeforeCookieExpires);
if (!(readCookie("_splash-entrance") === null)) {
link.href = readCookie("_splash-entrance");
} else {
link.href = "/";
}
}
};
}());
你認爲你需要改變這段代碼的哪一部分? 'expires = new Date(new Date()。getTime()+ parseInt(expires,10)* 1000 * 60 * 60 * 24);' – 2014-09-26 17:58:58
我厭倦了改變那行代碼,但它並不適用於我: expires = date.setTime(date.getTime()+(60 * 3000)); – user3188868 2014-09-26 22:01:42