<script type="text/javascript" language="javascript">
function iFrameHeight() {
var ifm = document.getElementById("iframepage");
var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument;
if (ifm != null && subWeb != null) {
ifm.height = subWeb.body.scrollHeight;
document.getElementById("tdpl").height = subWeb.body.scrollHeight;
}
}
</script>
<table width="98%" border="0"align="center" cellpadding="0" cellspacing="0">
<tr>
<td id=tdpl>
<iframe src=artpl.aspx?artid=<%=info.ID %> width=100% id="iframepage" onLoad="iFrameHeight()" frameborder=no scrolling=auto></iframe>
</td>
</tr>
</table>
本文介绍了一种使用JavaScript实现iframe自适应高度的方法。通过检测iframe内部文档的实际高度并动态调整iframe的高度,确保iframe始终能够精确适配其内容高度,避免多余滚动条出现的同时也优化了页面布局。

885

被折叠的 条评论
为什么被折叠?



