2014-03-04 218 views
0

我想在我的網站上添加一個彈出式Fb框,當訪問者向下滾動彈出窗口時會出現。我想當訪客點擊關閉按鈕時,彈出框將不會顯示15天。但是,當我點擊它的關閉,但是當我向上或向下滾動時顯示。請任何人都可以幫我嗎? 我的代碼是:如何防止彈出Facebook框,如果點擊關閉按鈕

<!-- FB Popup Likebox Start --> 
      <div class="fb-pop-like-box" id="fb-popup-like-box"> 
       <p style="text-align: center;">Hey, Like Us on Facebook!</p> 
       <div class="fb-like-box" data-href="https://www.facebook.com/ifo4all" data-width="300" data-height="200" data-colorscheme="light" data-show-faces="true" data-header="false" data-stream="false" data-show-border="true"></div> 
       <div class="no-show"><a href="#">Close: I already Like if04all!</a></div> 
      </div>  
       <script type="text/javascript"> 
        $(function() { 
         $("#fb-popup-like-box").hide(); 
         $(window).scroll(function() { 
          if ($(this).scrollTop() > 2100) { 
           $('#fb-popup-like-box').slideDown('slow'); 
          } else { 
           $('#fb-popup-like-box').slideUp('slow'); 
          } 
         }); 
        }); 
        jQuery(document).ready(function(){ 

        if(readFBCookie('squenched') != null) { 
           jQuery('#fb-popup-like-box').css("display", "none"); 
         } 

         jQuery('.no-show a').live("click",function(event){ 
          event.preventDefault(); 
          jQuery('#fb-popup-like-box').css("display", "none"); 
          var days=15; 
          var date = new Date(); 
          date.setTime(date.getTime()+(days*24*60*60*1000)); 
          var expires = "; expires="+date.toGMTString(); 
          document.cookie = "squenched=1"+expires+"; path=/"; 
          return false; 
         }); 
         function readFBCookie(name) { 
            var nameEQ = name + "="; 
            var ca = document.cookie.split(';'); 
            for(var i=0;i < ca.length;i++) { 
            var c = ca[i]; 
            while (c.charAt(0)==' ') c = c.substring(1,c.length); 
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 
            } 
            return null; 
         } 
        }); 
       </script> 
<!-- FB Popup Likebox Start End --> 

回答

0
$(function() { 
        $("#fb-popup-like-box").hide(); 
        $(window).scroll(function() { 
         if(readFBCookie('squenched') == null) { 
         if ($(this).scrollTop() > 2100) { 
          $('#fb-popup-like-box').slideDown('slow'); 
         } else { 
          $('#fb-popup-like-box').slideUp('slow'); 
         } 
         } 
        }); 
       }); 
       jQuery(document).ready(function(){ 

       if(readFBCookie('squenched') != null) { 
          jQuery('#fb-popup-like-box').css("display", "none"); 
        } 

        jQuery('.no-show a').live("click",function(event){ 
         event.preventDefault(); 
         jQuery('#fb-popup-like-box').css("display", "none"); 
         var days=15; 
         var date = new Date(); 
         date.setTime(date.getTime()+(days*24*60*60*1000)); 
         var expires = "; expires="+date.toGMTString(); 
         document.cookie = "squenched=1"+expires+"; path=/"; 
         return false; 
        }); 
        function readFBCookie(name) { 
           var nameEQ = name + "="; 
           var ca = document.cookie.split(';'); 
           for(var i=0;i < ca.length;i++) { 
           var c = ca[i]; 
           while (c.charAt(0)==' ') c = c.substring(1,c.length); 
         if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 
           } 
           return null; 
        } 

       }); 
+0

謝謝你很多關於答案,我是JS的一個菜鳥不顯示彈出式和CONSOL日誌「未捕獲的ReferenceError:readFBCookie沒有定義」 –

相關問題