关于iframe自适应高度。

最近在做一个网页效果的时候,碰到了iframe自适应高度的问题,几经周转总算差不多了。

<div class="r_content">
<iframe src="main.html" name="content" id="content" οnlοad="reinitIframe()" frameborder="0"></iframe>
<script type="text/javascript">
function reinitIframe(){
var iframe = document.getElementById('content');
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
if(height<570) height=570;
iframe.style.height =  height + 'px';
}catch (ex){}
}
//window.setInterval("reinitIframe()", 900);  //如果iframe里面要操作dom  增加或减少,可以开启这个。避免增加了或减少了借点而iframe高度不变。 谷歌浏览器要在服务器上运行才会有效果。
//window.setTimeout("reinitIframe()", 2000);
</script>
</div>	

贴出来,记录一下。

http://500px.com/photo/45519120 
http://500px.com/photo/45519118 
http://500px.com/photo/45519116 
http://500px.com/photo/45519110 
http://500px.com/photo/45519108 
http://500px.com/photo/45519106 
http://500px.com/photo/45519104 
http://500px.com/photo/45519102 
http://500px.com/photo/45519100 
http://500px.com/photo/45518470 
http://500px.com/photo/45518468 
http://500px.com/photo/45518466 
http://500px.com/photo/45518464 
http://500px.com/photo/45518462 
http://500px.com/photo/45517650 
http://500px.com/photo/45517648 
http://500px.com/photo/45517646 
http://500px.com/photo/45517644 
http://500px.com/photo/45517642 
http://500px.com/photo/45516818 
http://500px.com/photo/45516814 
http://500px.com/photo/45516812 
http://500px.com/photo/45516810 
http://500px.com/photo/45516806 
http://www.zhihu.com/collection/26321153
http://www.zhihu.com/collection/26322856
http://www.zhihu.com/collection/26323045


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值