我正试图学习设置一个JS Cookie,该Cookie会在一天后过期,但是我们的客户正在报告与此相关的间歇性结果。我想念什么吗?有没有更好的方法可以做到这一点?
老实说,我也愿意设置会话cookie来缓解问题,但是我想知道是否有人在我们首先在这里进行操作时发现了错误。
谢谢!
(function($){
checkCookie();
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 + ";path=/";
}
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 "";
}
function checkCookie() {
var noShowWelcome = getCookie("sameSessionSKF");
if (!noShowWelcome) {
$('#home-alert').modal({
fadeDuration: 500
});
setCookie('sameSessionSKF', true, 1); // sets to expire after 1 day
}
}
})(jQuery);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
答案 0 :(得分:1)
您可以指定true_vars = np.array([])
for idx in comparison:
if ((idx[1] == 'True') and (idx[2] == 'True') and (idx[3] == 'True')):
true_vars = np.append(true_vars, idx)
elif not exist ((idx[1] == 'True') and (idx[2] == 'True') and (idx[3] == 'True')):
print('there are no true ID's in comparison')
而不是expires
,它是cookie过期之前的秒数。
Max-Age