如何在Javascript中检查多个cookie
我正在尝试检查多个cookie,以便显示或不显示弹出窗口。只有在检查一个cookie,而不是两个cookie时,我所拥有的才有效如何在Javascript中检查多个cookie,javascript,cookies,popup,jquery-cookie,Javascript,Cookies,Popup,Jquery Cookie,我正在尝试检查多个cookie,以便显示或不显示弹出窗口。只有在检查一个cookie,而不是两个cookie时,我所拥有的才有效 $(window).load(function() { var delay = 5000; // milliseconds var cookie_expire = 30; // days (when to show visitor the popup again) //only show popup if the user doesn't have a
$(window).load(function() {
var delay = 5000; // milliseconds
var cookie_expire = 30; // days (when to show visitor the popup again)
//only show popup if the user doesn't have a "hide" cookie set or "Login" cookie set
if (($.cookie('hide_popup') != "1" && window.innerWidth > "800") || ($.cookie('Login') == "null" && window.innerWidth > "800")) {
$("#popup").delay(delay).fadeIn("fast", function() {
$("#popup-signup").load("/popup-content.php", function() {
$("#popup-signup").fadeIn("fast", function() {
});
});
});
//set the popup to not show again for the set period
$.cookie('hide_popup', '1', {
expires: cookie_expire,
path: '/'
});
//close popuop function
$("#closepopup").live("click", function() {
//hide popup
$("#popup, #popup-signup").hide();
$.cookie('hide_popup', '1', {
expires: cookie_expire,
path: '/'
});
});
}
});
我正在尝试设置cookie并检查登录名已设置的cookie。如果您想检查cookie是否不存在,我想您在这一行中所做的是:
if(($.cookie('hide_popup') != "1" && window.innerWidth > "800") || ($.cookie('Login') == "null" && window.innerWidth > "800"))
你必须做到:
if(($.cookie('hide_popup') != "1" && window.innerWidth > "800") || ($.cookie('Login') == null && window.innerWidth > "800"))
在上面的代码中,检查cookie的值是否为字符串null,而不是空值null。比较数字时,不应将数字括在引号中
if(($.cookie('hide_popup') != "1" && window.innerWidth > 800) || ($.cookie('Login') == null && window.innerWidth > 800))
{
当您与null进行比较时,不应将null括在引号中
if(($.cookie('hide_popup') != "1" && window.innerWidth > 800) || ($.cookie('Login') == null && window.innerWidth > 800))
{
cookie检查没有问题,因为它是一个字符串,所以1应该在引号中。您使用的是哪种过时的jQuery版本,仍然支持live?为什么要将数字与字符串进行比较?800不应该有引号。null不等于null这是我在网上找到的代码。我不是一个JavaScript程序员,我在PHP上工作,所以我理解的足够多,可以说是危险的。好吧,jQuery代码已经过时了,因为live已经在当前版本中被弃用和删除。
if(($.cookie('hide_popup') != "1" && window.innerWidth > 800) || ($.cookie('Login') == null && window.innerWidth > 800))
{