2017-10-18 34 views
1

嗨,我使用jquery cookie.js來存儲cookie。JQuery Cookie.js保存cokkie

我有搜索代碼和cookie.js插件它工作正常, 但我有一個問題,當我刷新頁面的cookie自動保存和彈出窗口不顯示。當任何用戶在網站上輸入彈出窗口,用戶必須點擊繼續按鈕進入網站,

我基本上不允許用戶在點擊繼續按鈕之前進入站點。

這裏是我的html代碼

<div id="popup-container"> 
<div class="wrapper"> 
<div id="popup-window"> 
    <div class="splash-bg"> 
    <h1>Are You Over 18? Click Continue if you are or return to previous 
     page</h1> 
    <a type="button" class="close">Continue</a> 
</div> 
</div> 

這是我使用

<script type="text/javascript"> 
    jQuery(document).ready(function(){ 
     jQuery('#popup-container a.close').click(function(){ 
      jQuery('#popup-container').fadeOut(); 
      jQuery('#active-popup').fadeOut(); 
     }); 

     var visits = jQuery.cookie('visits') || 0; 
     visits++; 

     jQuery.cookie('visits', visits, { expires: 1, path: '/' }); 

     console.debug(jQuery.cookie('visits')); 

     if (jQuery.cookie('visits') > 1) { 
     jQuery('#active-popup').hide(); 
     jQuery('#popup-container').hide(); 
     } else { 
      var pageHeight = jQuery(document).height(); 
      jQuery('<div id="active-popup"></div>').insertBefore('body'); 
      jQuery('#active-popup').css("height", pageHeight); 
      jQuery('#popup-container').show(); 
     } 

     if (jQuery.cookie('noShowWelcome')) { jQuery('#popup- 
     container').hide(); jQuery('#active-popup').hide(); } 
    }); 

    jQuery(document).mouseup(function(e){ 
     var container = jQuery('#popup-container'); 

     if(!container.is(e.target)&& container.has(e.target).length === 0) 
     { 
     container.fadeOut(); 
     jQuery('#active-popup').fadeOut(); 
     } 

    }); 
</script> 
+0

不檢查'> 1'。檢查的實際值,或者如果它是一個數字或者一個對象 – sheplu

+0

當有人刷新該cookie自動保存我希望找到能停止這種情況發生的解決方案...頁面 – usman

+0

我已經試過了,但它din't工作 – usman

回答

0

JS代碼當你有餅乾訪問的cookie的數量可能不是第一個cookie在cookie數組中,所以您必須嘗試使用​​以下兩種方式獲取該cookie:

jQuery.cookie('visits') 

jQuery.cookie(' visits') 
+0

對不起,我是新的js可以üPLZ解釋我這個... – usman

+0

console.log(document.cookie)你可以看到什麼? –

+0

我只是想通過刷新頁面來停止自動保存條件,除非用戶點擊繼續按鈕...這裏是我得到代碼的鏈接http://www.jqueryscript.net/lightbox/Cookie-Based- Modal-Popup-Plugin-For-jQuery-Popup-Window.html – usman