- 我有一个
customer.jsp
带有iframe
. iframe
有一个按钮。单击按钮时,我需要访问页面内的对话框customer.jsp
。- 我尝试过
window.parent.document.getElementById('formDialog');
,但正在获得null
价值。
问问题
25667 次
4 回答
8
window.parent.document.getElementById('target');
两个资源都应该在同一个来源
于 2013-02-20T05:14:16.667 回答
3
跨域资源无法在 iframe 和父文档之间进行通信。只有当 iframe 和包含页面来自相同的主机、端口和协议时,它才会起作用 - 例如http://example.com:80/1.html和http://example.com:80/2.html
Assuming both resources are from the same origin
在 iframe 中,window.parent 指的是父文档的全局对象,而不是文档对象本身。我相信你需要使用parent.document.getElementById('formDialog')
于 2013-02-20T05:06:23.490 回答
0
您可以通过以下方式访问父窗口元素parent.document.getElementById('formDialog');
如果你得到 null 你是否能够在该 iframe 父级的上下文中获取该元素?您是否引用了正确的 ID 和正确的父级?
于 2013-02-20T05:04:43.637 回答
0
尝试这个。希望这可以帮助。假设我通过点击 iframe 中的按钮获得 CallParentFunction。
function CallParentFunction(){
if (top && top.opener && top.opener.top) {
top.opener.document.getElementById('formDialog');
}
else {
top.document.getElementById('formDialog');
}
}
于 2013-02-20T05:26:02.560 回答