当前位置: 代码迷 >> Web前端 >> iframe 高度自适应 小结篇
  详细解决方案

iframe 高度自适应 小结篇

热度:5   发布时间:2012-10-30 16:13:36.0
iframe 高度自适应 总结篇
<iframe id="frame_content" src="iframe_b.html" scrolling="no" frameborder="0" onload="this.height=100"></iframe>   
  
<script type="text/javascript">   
  
function reinitIframe(){   
  
var iframe = document.getElementById("frame_content");   
  
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("reinitIframe()", 200);   
  
</script>  

?

如果只考虑FX和IE,并且,iframe里面内容也不进行DOM操作,那仍然可以用最简单的传统处理方式:

<iframe id="frame_content" src="iframe_b.html" scrolling="no" frameborder="0" onload="this.height=this.contentWindow.document.documentElement.scrollHeight"></iframe>  

?

这问题,我寻找了好多资料,都没这篇讲解的详细

?

?转自:http://lancijk.iteye.com/blog/621352

  相关解决方案