【发布时间】:2011-06-27 17:58:47
【问题描述】:
如何在 Chrome 中调用以下内容? iframe.contentWindow.document
【问题讨论】:
-
什么意思?这不是一个函数,所以你不会调用它。
-
我之前回答过这个问题:stackoverflow.com/questions/5002334/…
标签: javascript iframe google-chrome
如何在 Chrome 中调用以下内容? iframe.contentWindow.document
【问题讨论】:
标签: javascript iframe google-chrome
iframe.contentDocument 是你想要的。
【讨论】:
.defaultView.getComputedStyle of the iframe.contentDocument say ...Uncaught TypeError: Cannot call method 'getComputedStyle' of undefined ?
contentDocument 在它存在的地方更可取。
<iframe id="popupFrame" />
<script type="text/javascript">
var popupFrame = document.getElementById('popupFrame');
var iFrameDoc;
if (switchAccountsPopupFrame.document) {
iFrameDoc = switchAccountsPopupFrame.document; // works with IE9 and FF9
}
else {
// Google Chrome (16.0.912.75 m)
iFrameDoc = switchAccountsPopupFrame.ownerDocument;
}
....
</script>
【讨论】:
Chrome 确实支持iframe.contentWindow.document,但您可能会遇到一些问题:如果设置为iframe.src 属性的文件正在本地访问(即使用“file://”协议),该属性在 Chrome 中是不可访问的。如果您指定相对文件地址并尝试在不使用 IIS 或 Apache 之类的 Web 服务器(只需双击它)的情况下测试脚本,就会发生这种情况。这同样适用于iframe.contentDocument。
我遇到了类似的问题,由于某种奇怪的原因,Chrome 不接受动态附加到 iframe 的事件处理程序。然后我在this article找到了这个note,用Apache测试过,嘿嘿,突然就开始工作了。
【讨论】: