现在的位置: 首页 > 综合 > 正文

Ifram 内页面高度自适应 兼容FF IE

2013年08月13日 ⁄ 综合 ⁄ 共 1062字 ⁄ 字号 评论关闭

 

 

< i frame  id=rightframe name=rightframe src="admin_right.aspx" marginWidth="10" frameSpacing="0" marginHeight="0" frameBorder="0" scrolling="no" align="center" width=785 height="1" frameborder="no" onload='this.height="500px";this.height=rightframe.document.body.scrollHeight;'   ></ i frame>

 

注:onload='this.height="500px"; 这个是为了避免有的页面很长,切到短页面,还是很长这个问题

写成JS函数形式

 

<script type="text/javascript">
function reiframe(){
var iframe=document.getElementById("dlok");
try{
var bheight=iframe.contentWindow.document.body.scrollHeight;
var dheight=iframe.contentWindow.document.documentElement.scrollHeight;
var height=Math.max(bheight,dheight);
iframe.height=height;
}catch(ex){}
}
window.setInterval("reiframe()",200);
</script>

 

 

上面的在w3c就不能正确用了,IE正确,但ff会显示不出来因为它不认识body.scrollHeight

它只认识documentElement.scrollHeight;

所以改成

< i frame  id=rightframe name=rightframe src="admin_right.aspx" marginWidth="10" frameSpacing="0" marginHeight="0" frameBorder="0" scrolling="no" align="center" width=785 height="1" frameborder="no" onload='this.height="500px";this.height=rightframe.document.documentElement.scrollHeight;'   ></ i frame>

抱歉!评论已关闭.