由于不想使用滚动条,又不想固定框架的高度,想使他根据内容的多少而自动调整高度。
1. 主页面的框架代码:
<iframe id="ifr" src="test.html" width="660" frameborder="0" scrolling="no" name="aa" id="aa"></iframe>
2. 所嵌套子页面test.html在head添加脚本:
代码
<script language="JavaScript" type="text/javascript">
function f_frameStyleResize(targObj) {
var targWin = targObj.parent.document.all[targObj.name];
if (targWin != null) {
var HeightValue = targObj.document.body.scrollHeight
if (HeightValue < 500) { HeightValue = 500 }
targWin.style.pixelHeight = HeightValue;
}
}
function f_iframeResize() {
bLoadComplete = true; f_frameStyleResize(self);
}
var bLoadComplete = false;
window.onload = f_iframeResize;
</script>
function f_frameStyleResize(targObj) {
var targWin = targObj.parent.document.all[targObj.name];
if (targWin != null) {
var HeightValue = targObj.document.body.scrollHeight
if (HeightValue < 500) { HeightValue = 500 }
targWin.style.pixelHeight = HeightValue;
}
}
function f_iframeResize() {
bLoadComplete = true; f_frameStyleResize(self);
}
var bLoadComplete = false;
window.onload = f_iframeResize;
</script>
作者:陈敬(公众号:敬YES)
出处:http://www.cnblogs.com/janes/
博客文章仅供交流学习,请勿用于商业用途。如需转载,请务必注明出处。