【发布时间】:2011-06-11 02:29:13
【问题描述】:
<script language="JavaScript">
function autoResize(id){
alert('check');
var newheight;
var newwidth;
if(document.getElementById){
newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
}
alert(newheight);
alert(newwidth);
document.getElementById(id).height= (newheight) + "px";
document.getElementById(id).width= (newwidth) + "px";
}
</script>
HTML:
<iframe id="faq_iframe" src="http://www.google.com" width="100%" height="200px" scrolling="no" frameborder="0" marginheight="0" onload="javascript: autoResize('faq_iframe');"></iframe>
问题:我正在使用 iframe 来显示我的页面。我需要使 iframe 适合我的页面高度我该怎么做。
上面的代码我试过了
我通过萤火虫得到了这个错误
Permission denied for <http://localhost> to get property Window.document from <http://www.google.co.in>.
[Break On This Error] newheight=document.getEleme...tWindow.document.body.scrollHeight;
如何使 iframe 的高度适合 iframe src 中给定的页面高度
【问题讨论】:
标签: javascript jquery html iframe