2016-08-23 67 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 –