iframe框架高度自适应的实现

来源:互联网 发布:mac excel 日期快捷键 编辑:程序博客网 时间:2024/05/17 02:49

解决iframe框架页面自适应高度问题代码如下,需要注意的是框架引用页面一定要设置name属性,否则会不生效

方案一:
<iframe src="test.asp" width="100%" frameborder="0" scrolling="no" name="hj" id="hj"></iframe>

test.asp页面head间增加如下JS代码

<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} 

  targWin.style.pixelHeight = HeightValue;

 }

}

function f_iframeResize(){

 bLoadComplete = true; f_frameStyleResize(self);

}

var bLoadComplete = false;

window.onload = f_iframeResize;

</SCRIPT>  

方案二:

<iframe name="I1" src="product_in.asp" onload="document.all('I1').style.height=I1.document.body.scrollHeight;" border="0" frameborder="0" width="605" height="346" style="border-style: solid; border-width: 0; padding: 0" marginwidth="1" marginheight="1" scrolling="no"></iframe>

 
原创粉丝点击