我有一个父页面和子页面为 jquery 事件共享相同的 file.js 文件。
我正在使用 Magnific Popup
并且我有:
$("#addDetailButton").magnificPopup({
items: {
src: 'someURL'
},
type: 'iframe',
enableEscapeKey: false,
modal: true
});
我的弹出窗口基于 iframe
并且是 modal
。如何使用 button
html 元素关闭模态窗口?我对 StackOverflow 和所有基于 inline
类型的回复进行了研究。
我试过了
<input id="cancel" type="button" value="Cancel"/> // child page
$("#cancel").click(function(){
$.magnificPopup.close();
});
我总是通过 Firefox 的 Web 控制台收到以下内容:
TypeError: $.magnificPopup is undefined
谢谢
最佳答案
Iframe 有自己的范围,它不能直接访问周围的范围。但是您可以在主窗口中使用父全局变量。
试试这个:
parent.$.magnificPopup.close();
您可以在此处找到有关此主题的更多信息:Calling a parent window function from an iframe
关于javascript - 通过按钮关闭一个iframe类型的弹出模态窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26044295/