从iFrame将模式窗口打开到父窗口 [英] opening modal window from iFrame into parent window
问题描述
我需要一些帮助,将iFrame的模式附加到其父主体.我听说过jQuery插件 SimpleModal ,甚至尝试过,但失败了.
I need some help appending a modal from an iFrame to it's parent body. I've heard about the jQuery plugin SimpleModal and even tried it, but failed.
因此,我有一个包含iFrame的页面,并且在此iFrame中有一个按钮,应在父窗口中打开模式窗口.问题是我无权将代码放入父窗口.我只能访问iFrame.
So I have a page with an iFrame and inside this iFrame there is a button that should open a modal window in the parent window. The problem is that I don't have access to put code into the parent window. I just have access to the iFrame.
对于任何帮助,我都非常感谢!
For any kind of help, I'm very thankful!
推荐答案
没有任何示例代码,很难按照您的确切布局向您展示,但是我可以举一个例子说明如何实现此目的.请记住,所有内容都必须在同一个域中,我以为是这样.
Without any example code, it's kinda hard to show you per your exact layout, but I can give you an example of how I've achieved this. Keep in mind, everything must be on the same domain, which I would assume it is.
我必须为自己开发的CRM做到这一点,这是我如何做到的一个示例:
I had to do this for a CRM I've developed and here's an example of how I did it:
<body>
<div id="myModal">stuff</div>
父级JS
<script>
$(function() {
$('#myModal').someDialogPlug({ some: options });
})
</script>
iFrame HTML
<button id="btnPopModal">click me</button>
iFrame JS
<script>
$(function() {
$('#btnPopModal').on('click', function(e) {
// here's the fun part, pay attention!
var $body = $(window.frameElement).parents('body'),
dlg = $body.find('#myModal');
dlg.someDialogPlugin('open');
});
})
</script>
这篇关于从iFrame将模式窗口打开到父窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!