半神半圣亦半仙,全儒全道是全闲,脑中真书藏万贯,掌握文武半边天。
Apr
17
今天在工作中因为iframe的内容不固定,有时高有时低,需要让iframe自适应高度,于是在网上找到了如下解决方法,可以选择使用:
1.在包含Iframe的页面:
关键语句在于onload="this.height=this.document.body.scrollHeight"。
2.在包含Iframe的页面:
然后在每个要在Iframe中显示的页面底部加入
1.在包含Iframe的页面:
<iframe name="iframe1" src="main.jsp" width="557px" height="100%" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" onload="this.height=iframe1.contentWindow.document.body.scrollHeight"></iframe>
关键语句在于onload="this.height=this.document.body.scrollHeight"。
2.在包含Iframe的页面:
<iframe name="iframe1" src="main.asp" width="557px" height="100%" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" onload="getHeight()"></iframe>
然后在每个要在Iframe中显示的页面底部加入
<div id="End"></div>
<script language="JavaScript">
function getHeight(){
iframe1.height=document.getElementById("End").offsetTop+10;
}
</script>
<script language="JavaScript">
function getHeight(){
iframe1.height=document.getElementById("End").offsetTop+10;
}
</script>




