我很难在1周后设置cookie重置时间。有谁知道如何实现这一目标?我在Shopify主题中使用以下代码。我现在只能选择显示一次或在我的主题设置中显示它。
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}
期待您的回复。干杯!
答案 0 :(得分:1)
尝试这样的事情?花一分钟的时间。将它乘以60将其变为秒。
var d = new Date();
var minutes = 10080;
d.setTime(d.getTime() + (minutes * 60));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;