2014-09-25 63 views
1

我有一個父頁面和子頁面共享file.js文件爲jquery事件。通過按鈕關閉一個彈出式iframe類型的模式窗口

嗯,我正在與Magnific Popup工作,我有:

$("#addDetailButton").magnificPopup({ 
     items: { 
       src: 'someURL' 
     }, 
     type: 'iframe', 
     enableEscapeKey: false, 
     modal: true 

}); 

我的彈出是基於iframemodal。如何使用button html元素關閉模式窗口?我對StackOverflow和所有回覆進行了研究,並且基於inline類型。

我已經試過

<input id="cancel" type="button" value="Cancel"/> // child page 

$("#cancel").click(function(){ 
     $.magnificPopup.close(); 
}); 

,我總是收到以下槽Firefox的Web控制檯:

TypeError: $.magnificPopup is undefined 

謝謝

回答

2

一個I幀有它自己的範圍就不能訪問直接圍繞範圍。但是你可以用父全局變量在主窗口中加入。

試試這個:

parent.$.magnificPopup.close(); 

你可以找到更多關於這個話題在這裏:Calling a parent window function from an iframe

+0

非常感謝你。 – 2014-09-25 23:01:04

相關問題