ITeye博客

iframe 框架 高度 自适应 问题

nash01 · 2011-05-23 20:57 · Web前端 · Markdown

js代码


<script type="text/javascript">
	function reinitIframe(frame){
		var iframe = document.getElementById(frame);
		try{
			var bHeight = iframe.contentWindow.document.body.scrollHeight;
                         var dHeight =iframe.contentWindow.document.documentElement.scrollHeight;
			var height = Math.min(bHeight, dHeight);
			//如果高度小于500的话,则iframe的默认高度是500px;
                        if (height < 500) {
				height = 500;
			}
			
			iframe.height =  height;
		}catch (ex){}
	}
	//在前台(界面)每隔200毫秒就刷新一下
	window.setInterval("reinitIframe('right_content')", 200);
                                                                              
</script>


html代码

//有一个iframe的id是right_content


<div id="content">
	<iframe src="" id="right_content" scrolling="no"></iframe>
</div>

评论(0)

暂无评论。

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