有时为了方便使用iframe,但被潜入的页面长度不是固定的,显示滚动条不仅影响美观还对用户操作带来不便,自动调整高度可以解决这个问题。^_^
<script language="javascript">
function f_framestyleresize(targobj){
var targwin = targobj.parent.document.all[targobj.name];
if(targwin != null) {
var heightvalue = targobj.document.body.scrollheight
if(heightvalue < 600){heightvalue = 600} //不小于600
targwin.style.pixelheight = heightvalue;
}
}
function f_iframeresize(){
bloadcomplete = true; f_framestyleresize(self);
}
var bloadcomplete = false;
window.onload = f_iframeresize;
</script>
注意:iframe必须要有name属性,否则无效。