由于不想使用滚动条,又不想固定框架的高度,想使他根据内容的多少而自动调整高度。
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>