【发布时间】:2015-02-17 11:30:36
【问题描述】:
这是我的问题:
- iframe 在父窗口中打开;
- 在 iframe(js 文件)中加载的函数用于修改位于 iframe 中的 DOM;
在 iframe 中使用时,该功能运行良好:
$(DOMId).function();
我正在努力从父窗口做同样的事情,但没有成功...... 我总是得到 xxx。'function' 不是函数。
我尝试从加载的脚本中直接访问函数和变量,没有问题。例如: jQuery(iframeId)[0].contentWindow.direcfunction();
但我找不到在 iframe 中调用附加到 DOM 的函数的方法。 我尝试了很多东西,最新的是:
var iframeDOM = document.getElementById(iframeId).contentDocument.getElementById(DOMId); jQuery(iframeDOM).function();
有没有人解决这个问题?
【问题讨论】:
-
由于安全问题,如果您在不同的域中,则无法访问 iframe。
-
试试:
document.getElementById(iframeId).contentDocument.$("#"+DOMId).function() -
同域,没有跨域内容。
-
A. Wolff:返回 'document.getElementById(iframeId).contentDocument.$' 不是函数。
-
对不起:
document.getElementById(iframeId).contentWindow.$("#"+DOMId).function()并且仅在 iframe 加载后调用它,因此可以根据用例在 iframe onload 事件甚至窗口 onload 事件中设置
标签: javascript jquery dom iframe