2014-02-20 214 views
5

任何人都可以告诉我如何使用弹出式窗口jquery插件(使用ajax)打开弹出窗口。如何打开弹出式窗口中的弹出式窗口的插件

$('.ajax-popup-link').magnificPopup({ 
    type: 'ajax' 
}); 
<a href="path-to-file.html" class="ajax-popup-link"> Link 1 </a> 

开启 “路径到file.html”

<a href="path-to-other-file.html" class="ajax-popup-link"> next popup </a> 

感谢

回答

5

你不能有两个窗口同时打开。但弹出的内容在第二次调用时会被替换,下面是示例 - http://codepen.io/dimsemenov/pen/hwIng

+2

喜,其内嵌的内容,我想用ajax! –

+0

你会如何做到这一点无限链接弹出窗口动态导航帖子例如@DmitrySemenov – josethernandezc

+2

这不适用于ajax,因为它只替换内容而不是选项等。这实际上是可能的吗?似乎限制,如果没有。 – Paul

1

只要您在通过ajax提取的页面中存在下一个和上一个链接,就可以这样做。

这为我工作:

$('.js-pack').magnificPopup({ 
    delegate: '.js-mfp-ajax', 
    type: 'ajax', 
    closeOnBgClick: false, 
    mainClass: 'mfp-fade', 
    removalDelay: 300, 
    overflowY: 'scroll', 
    gallery: { 
     enabled: true 
    }, 
    callbacks: { 
     ajaxContentAdded: function() { 
      $('.prev-next .next-link').click(function(event){ event.preventDefault(); $.magnificPopup.next(); }); 
      $('.prev-next .prev-link').click(function(event){ event.preventDefault(); $.magnificPopup.prev(); }); 
     } 
    } 
}); 

他们关键部位增加是gallery: enabledcallbacks参数。

我的下一个上一个按钮的HTML很简单:

<div class="prev-next"> 
    <a class="btn prev-link" href="http://prev-url" rel="prev">« Previous</a> 
    <a class="btn next-link" href="http://next-url" rel="next">Next »</a> 
</div> 
1

您可以通过一个简单的Ajax请求做到这一点:

$('a.your-link').on('click',function(e){ 
    e.preventDefault(); 
    $.ajax({ 
     type: "GET", // or POST 
     url: 'url_to_php_page.php', 
     data: { 
      get_request_id : $(this).data('id'), // assign a data-id to the link 
     },          
     success: function(data){ 
      $.magnificPopup.open({ 
       type: 'inline', 
       closeOnContentClick: false, 
       items: { 
        src: data 
       } 
      }) 
     } 
    }); 
}); 

然后在服务器端,您检索get_request_id$_GET['get_request_id']$_POST['get_request_id']

2

我这知道一个古老的线程,但仍然有人感兴趣,这个工作对我来说:

$(document).on('click', '.sAjax', function(e){ 

     $.magnificPopup.close(); // Close existing popup 

     // Open new popup 
     $.magnificPopup.open({ 
      items: { 
       src: 'new-page.html', 
       type: 'ajax' 
      } 
     }); 

     e.preventDefault(); 

}); 

不要忘记给你的链接的新类的.sAjax