根据内容自动调整IFrame高度

来源:互联网 发布:修改mysql引擎 编辑:程序博客网 时间:2024/05/16 18:38

有时为了方便使用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属性,否则无效。

 

原创粉丝点击