2014-02-18 30 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); 
    }; 
相關問題