ITeye博客

怎么让iframe的高度根据所加载页的高度而改变

highping · 2009-04-06 22:47 · Markdown

解决思路:
        如果页面没有加载完成是无法知道它的高度的,所以不能直接设置,而必须通过iframe的onload事件来触发脚本,在 iframe 加载完后重新设置它的高为所加载文档的滚动高度。
        具体步骤:
        1.包含框架页的代码。

<iframe frameborder="0" scrolling="no" name="demo"  
onload="document.all.demo.height=document.frames[’demo’].document.body.scrollHeight" src="demo.htm" width="100%"></iframe> 

 

        2.demo.htm页代码。

 

<body bgColor="#EEEEEE"> 
<script> 
       document.write(new Array(100).join("1<br>")) 
</script> 

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。