当前位置: 代码迷 >> Web前端 >> iframe 框架 高度 自适应 有关问题
  详细解决方案

iframe 框架 高度 自适应 有关问题

热度:493   发布时间:2012-11-22 00:16:41.0
iframe 框架 高度 自适应 问题
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>


  相关解决方案