2016-08-23 73 views
-1

我有这个脚本,如果没有cookie,它将显示一个模式。 第一个如果存在cookie,则隐藏模式 和“ELSE”(如果没有cookie),它将显示它。include document.referrer in“else if”

我需要添加一个document.referer条件如下。

除了验证cookie是否存在以外,请检查引用者(以下相同的功能),然后才显示该模式。

代码:

jQuery(document).ready(function() { 
 
    if (jQuery.cookie('visits') > 0.5) { 
 
    jQuery('#active-popup').hide(); 
 
    jQuery('#popup-container').hide(); 
 
    jQuery('html, body').removeAttr('style'); 
 
    } else { 
 
    var pageHeight = jQuery(document).height(); 
 
    jQuery('<div id="active-popup"></div>').insertBefore('body'); 
 
    jQuery('#active-popup').css("height", pageHeight); 
 
    jQuery('#popup-container').show(); 
 
    jQuery('html, body', window.parent.document).css({ 
 
     'overflow': 'hidden', 
 
     'height': '100%' 
 
    }); 
 
    } 
 

 
    $(document).ready(function() { 
 
    $('#popup-container').css({ 
 
     'left': (Math.floor(Math.random() * 15) + 3) + '%' 
 
    }) 
 
    $('#popup-container').css({ 
 
     'top': (Math.floor(Math.random() * 23) + 33) + '%' 
 
    }) 
 
    }); 
 
});

的参考

if (document.referrer) { 
    facebook = /facebook.com/; 
    if (facebook.test(document.referrer)) { 

    } 
    } 
+1

我不知道是什么问题? 你只是试图改变“else if(document.referrer && facebook.test(document.referrer))”中的“else”吗? –

回答

2

变化elseelse if你想要的状态。

jQuery(document).ready(function() { 
 
    facebook = /facebook\.com/; 
 
    if (jQuery.cookie('visits') > 0.5) { 
 
    jQuery('#active-popup').hide(); 
 
    jQuery('#popup-container').hide(); 
 
    jQuery('html, body').removeAttr('style'); 
 
    } else if (document.referrer && facebook.test(document.referrer)) { 
 
    var pageHeight = jQuery(document).height(); 
 
    jQuery('<div id="active-popup"></div>').insertBefore('body'); 
 
    jQuery('#active-popup').css("height", pageHeight); 
 
    jQuery('#popup-container').show(); 
 
    jQuery('html, body', window.parent.document).css({ 
 
     'overflow': 'hidden', 
 
     'height': '100%' 
 
    }); 
 
    } 
 

 
    $(document).ready(function() { 
 
    $('#popup-container').css({ 
 
     'left': (Math.floor(Math.random() * 15) + 3) + '%' 
 
    }) 
 
    $('#popup-container').css({ 
 
     'top': (Math.floor(Math.random() * 23) + 33) + '%' 
 
    }) 
 
    }); 
 
});

+0

谢谢Barmar:D 我通过document.referrer更改了document.referer,但不起作用。 :( 任何想法? –

+0

啊现在工作:D谢谢你:D –