【发布时间】:2013-10-21 12:18:50
【问题描述】:
请检查下面我的代码 -
<script>
function autoResize(myiframe){
var newheight;
var newwidth;
if(document.getElementById){
newheight=document.getElementById(myiframe).contentWindow.document.body.scrollHeight;
newwidth=document.getElementById(myiframe).contentWindow.document.body.scrollWidth;
}
document.getElementById(myiframe).height= (newheight+20) + "px";
document.getElementById(myiframe).width= (newwidth) + "px";
}
</script>
<iframe id="myiframe" src="http://www.learnphp.in" width="100%" onload="autoResize('myiframe')"></iframe>
我已经更改了这段代码,但是当我使用相对路径(内部页面)时工作正常,例如files/test.html、mypage.html 等。但它不适用于绝对路径(外部页面),例如 http://www.learnphp.in
请建议我如何在 iframe 中显示外部页面自动高度?
【问题讨论】:
标签: javascript html css iframe