如何选择此iframe的子级? [英] How do I select the child of this iframe?
问题描述
<div id="google" class="ui-tabs-panel" style="display: block;">
<iframe id="fre" name="fre" src="http://www.google.com/search?q=xxxx">
<html>
.....
</html>
</iframe>
</div>
我要使iframe的高度等于html的高度像这样
I want to make the iframe height equal to the html height like this
document.getElementById("fre").style.height.value =
document.getElementById("???").style.height();
如何选择html?
即使我设法选择它,也可以使用iframe来做到这一点吗?
Even if I manage to select it, is it possible to do that with an iframe?
推荐答案
我记得,除非来自同一域,否则您无法访问iframe源的DOM.
As I recall, you can't access the DOM of an iframe's source unless it's from the same domain.
因此,假设父/iframe位于同一域上,则需要iframe的 contentWindow
1 属性...,您可以从中检索文档./p>
So, provided the parent/iframe are on the same domain you'll want the iframe's contentWindow
1 property... from which you can retrieve the document.
var frame = document.getElementById("fre");
var frameDoc = frame.contentWindow.document;
frame.style.height = frameDoc.getElementById("childElementId").style.height;
1 参见 HTMLIframeElement. contentWindow
.根据您的浏览器,您可能拥有 contentDocument
属性来代替 contentWindow
.
1 See HTMLIframeElement.contentWindow
. Depending upon your browser, you may have a contentDocument
property in lieu of contentWindow
.
这篇关于如何选择此iframe的子级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!