七郎's JavaBlog

草木竹石皆可為劒。至人之用人若鏡,不將不迎,應而不藏,故能勝物而不傷。
posts - 60, comments - 14, trackbacks - 0, articles - 0

iframe自适应高度

Posted on 2008-08-03 01:04 七郎归来 阅读(329) 评论(0)  编辑  收藏
方法1:
<iframe   name="iframe"   src="0206showOperationLog.jsp" height="0" frameborder="0" scrolling="no" width="800" onload = "height = document.frames(this.name).document.body.scrollHeight"
  </iframe>  
 height="0"的作用为开始没有数据时 iframe不显示
方法2:
<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>

只有注册用户登录后才能发表评论。


网站导航: