2014-02-18 31 views
4

我目前有一个大的弹出窗口,并且在那个弹出窗口中,我有一个链接打开另一个大的弹出窗口。沿着线的东西:当从另一个窗口打开一个大的弹出窗口时,回调不会触发

$('.logbook-entry-details').magnificPopup({ 
    type: 'ajax', 
    closeBtnInside:true, 
    closeOnBgClick:false, 
    closeOnContentClick:false, 
    callbacks: { 
     beforeOpen: function() { 
      $.magnificPopup.close(); 
     }, 
     open: function() { 
      console.log('Popup open has been initiated'); 
      }, 
      beforeClose: function() { 

      console.log('Popup before close has been initiated'); 
      }, 
     close: function() { 
      console.log('Popup close has been initiated'); 

      }, 
     afterClose :function() { 
      console.log('Popup after close has been initiated'); 
      } 
     } 
}); 

阅读后,我发现,在第二弹出回调将不会被并注册,直到我关闭原始弹出如打开新的一个刚刚替换内容其实没有重新建立一个新的实例。

我想弄清楚如何在弹出窗口中关闭当前弹出窗口,然后调用代码打开新窗口,以便它可以注册我的回调。

顺便说一句,我试图做到这一点的原因是我想关闭我的新弹出后重新打开原始弹出。如果你碰巧有更好的解决方案,请告诉我。

回答

5

所以,如果有人需要这个答案,我不得不将下面的代码添加到我的新弹出。

// a button that closes the popup 
$('#cancel-logbook-entry-btn').click(function(){ 
$.magnificPopup.proto.close.call(this); 
}); 

$.magnificPopup.instance.close = function() { 

//code to show the original popup 
}; 

然后在弹出原来我不得不添加,否则它永远不会关闭弹出

$.magnificPopup.instance.close = function() { 
     // "proto" variable holds MagnificPopup class prototype 
     // The above change that we did to instance is not applied to the prototype, 
     // which allows us to call parent method: 
     $.magnificPopup.proto.close.call(this); 
    }; 
相关问题