2017-03-21 90 views
1

試圖顯示這個彈出每次訪問一次。我覺得我失去了一些東西顯示彈出一次(蕩氣迴腸彈出)

<script src="http://code.jquery.com/jquery-1.7.min.js"> 
<link href="http://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css" rel="stylesheet" type="text/css" media="all"/> 
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script> 
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.js"></script> 

<script> 
$(document).ready(function() { 
var check_cookie = $.cookie('bsw'); 
    if(check_cookie == null){ 
    $.cookie('bsw', 'yes', {expires: 1 }); 
    $('.image-link').magnificPopup({type:'image'}); 
}); 
</script> 

<script> 
(function($) { 
    $(window).load(function() { 
     // retrieved this line of code from http://dimsemenov.com/plugins/magnific-popup/documentation.html#api 
     $.magnificPopup.open({ 
      items: { 
       src: '/bsw-10-off.png' 
      }, 
      type: 'image' 

      // You may add options here, they're exactly the same as for $.fn.magnificPopup call 
      // Note that some settings that rely on click event (like disableOn or midClick) will not work here 
     }, 0); 
    }); 
})(jQuery); 
</script> 

我沒有關閉或打開一些東西嗎?我覺得這個問題在文檔準備好的功能之內,但我可能是錯的。任何幫助,將不勝感激。謝謝。

下面是一個沒有Cookie代碼的代碼

<link href="http://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css" rel="stylesheet" type="text/css" media="all"/> 
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script> 

<script> 
$(document).ready(function() { 
    $('.image-link').magnificPopup({type:'image'}); 
}); 
</script> 

<script> 
(function($) { 
    $(window).load(function() { 
     // retrieved this line of code from http://dimsemenov.com/plugins/magnific-popup/documentation.html#api 
     $.magnificPopup.open({ 
      items: { 
       src: 'http://www.barbershopwindow.com/bfimages/bsw-10-off.png' 
      }, 
      type: 'image' 

      // You may add options here, they're exactly the same as for $.fn.magnificPopup call 
      // Note that some settings that rely on click event (like disableOn or midClick) will not work here 
     }, 0); 
    }); 
})(jQuery); 
</script> 
+0

你從來沒有提到什麼是不工作的。 –

+0

首先,你的Cookie代碼中的'if'有一個丟失的大括號。 –

+0

問題是它不斷出現 – MHeredia

回答

0

相反的:

//獲取來自http://dimsemenov.com/plugins/magnific-popup/documentation.html#api

這行代碼,你可以簡單地點擊觸發事件後,初始化你的magnificPopup。

此外,$ .cookie( 'BSW')收益不確定和不爲空,如果cookie不存在。

工作jsfiddle

$(document).ready(function() { 
    var check_cookie = $.cookie('bsw'); 
    if (check_cookie == undefined) { 
     $.cookie('bsw', 'yes', {expires: 1}); 
     $('.image-link').magnificPopup({type: 'image'}).trigger('click'); 
    } 
}); 
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script> 
<link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css" rel="stylesheet"/> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.js"></script> 



<a class="image-link" href="http://farm4.staticflickr.com/3721/9207329484_ba28755ec4_o.jpg">Open popup</a> 
+0

太棒了。這工作!謝謝你這麼多 – MHeredia

+0

從事過小提琴,但即時通訊沒有得到一個現成不在控制檯上我的網站功能錯誤 – MHeredia

+0

貌似是jQuery的與該 – MHeredia