If I open a dialog like so:
如果我打开这样的对话框:
$('<iframe id="externalSite" class="externalSite" src="http://www.example.com" />').dialog({
autoOpen: true,
width: 800,
height: 500,
modal: true,
resizable: true
})
How can I close the dialog from withing the iframe?
我怎样才能把对话框从iframe中关闭呢?
3 个解决方案
#1
23
OK so I put the iframe on the page with display set to none. I open it like this:
我把iframe设置为none的页面。我这样打开它:
$('#externalSite').dialog({ ... });
on the main parent window I have a function like this:
在主父窗口中,我有一个这样的函数:
function closeIframe()
{
$('#externalSite').dialog('close');
return false;
}
From within the iframe I call:
我在iframe中调用:
window.parent.closeIframe();
#2
6
Simply calling the following worked for me:
简单地给我打以下电话就可以了:
window.parent.$('#externalSite').dialog('close');
window.parent。$(' # externalSite ').dialog(“关闭”);
#3
0
Have you tried this?:
你试过这个吗?
$(window.parent).dialog('close');
I have never used the jQuery UI dialog, so I'm not sure that will actually work. It seems to me that you would need to maintain a reference to the dialog you created so that you can use it to close the dialog.
我从来没有使用过jQuery UI对话框,所以我不确定这是否真的有效。在我看来,您需要维护您创建的对话框的引用,以便您可以使用它来关闭对话框。
Note, you could also look for elements in the parent's DOM by:
注意,您还可以通过以下方法在父DOM中查找元素:
$('#someParentDOMElement' , window.parent);
Of course, all of this is assuming that the site you load within the iframe
is on the same domain as the parent document. If not, then the document in your iframe
will not have access to the parent DOM at all.
当然,所有这些都假设在iframe中加载的站点与父文档位于同一域。如果没有,那么iframe中的文档将根本无法访问父DOM。
#1
23
OK so I put the iframe on the page with display set to none. I open it like this:
我把iframe设置为none的页面。我这样打开它:
$('#externalSite').dialog({ ... });
on the main parent window I have a function like this:
在主父窗口中,我有一个这样的函数:
function closeIframe()
{
$('#externalSite').dialog('close');
return false;
}
From within the iframe I call:
我在iframe中调用:
window.parent.closeIframe();
#2
6
Simply calling the following worked for me:
简单地给我打以下电话就可以了:
window.parent.$('#externalSite').dialog('close');
window.parent。$(' # externalSite ').dialog(“关闭”);
#3
0
Have you tried this?:
你试过这个吗?
$(window.parent).dialog('close');
I have never used the jQuery UI dialog, so I'm not sure that will actually work. It seems to me that you would need to maintain a reference to the dialog you created so that you can use it to close the dialog.
我从来没有使用过jQuery UI对话框,所以我不确定这是否真的有效。在我看来,您需要维护您创建的对话框的引用,以便您可以使用它来关闭对话框。
Note, you could also look for elements in the parent's DOM by:
注意,您还可以通过以下方法在父DOM中查找元素:
$('#someParentDOMElement' , window.parent);
Of course, all of this is assuming that the site you load within the iframe
is on the same domain as the parent document. If not, then the document in your iframe
will not have access to the parent DOM at all.
当然,所有这些都假设在iframe中加载的站点与父文档位于同一域。如果没有,那么iframe中的文档将根本无法访问父DOM。