开发者

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>

I want to make the iframe height equal to the html height like this

document.getElementById("fre").style.height.value = 
document.getElementById("???").style.height();

How do I select the html ?

Even if I manage to select it, is it possible to do that with an ifra开发者_高级运维me?


As I recall, you can't access the DOM of an iframe's source unless it's from the same domain.

So, provided the parent/iframe are on the same domain you'll want the iframe's contentWindow1 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 See HTMLIframeElement.contentWindow. Depending upon your browser, you may have a contentDocument property in lieu of contentWindow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜