我有一个带有2个按钮的年龄选通页面。按钮1 =“低于18”,按钮2 =“高于18”。
如果用户转到另一个页面,则年龄限制并且没有存储的cookie,我正在自动重定向到年龄限制。我不知道为什么,但是即使当我存储cookie时,我也一直都在重定向。有什么想法我做错了吗?
谢谢!
function checkCookie() {
var age = getCookie("ageVerify");
if (age === "over18") {
// Check cookie: if exists and age passes, allow user into site
setCookie("ageVerify", "over18", 1);
} else {
$('#aboveAge').on('click', function() {
// If user responds yes, change age value
age = "over18";
setCookie("ageVerify", "over18", 1);
});
$('#belowAge').on('click', function() {
// If user clicks cancel, direct user to /under-21 page
setCookie("ageVerify", "under18", 1);
});
}
var url = location.pathname;
if((url.indexOf('/jim-beam/age-gate/') > -1) && (age != "over18")) {
} else if((url.indexOf('/jim-beam/age-gate/') > -1) && (age === "over18")) {
} else if (age === "over18") {
} else {
window.location.replace("/jim-beam/age-gate/");
}
}