iframe自适应高度(兼容IE6、IE7、IE8、fireFox、Chrome)

 

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
   "http://www.w3.org/TR/html4/frameset.dtd">
   
<HTML>

	<HEAD>
		<TITLE>乐曦主页</TITLE>
	</HEAD>
	
	<link rel="stylesheet" type="text/css" href="style/main.css">
	
	<script type="text/javascript">
		function SetCwinHeight() { 
			var iframeid = document.getElementById("center"); //iframe id 
			iframeid.height = "0px";//先给一个够小的初值,然后再长高. 
			if (document.getElementById) { 
				if (iframeid && !window.opera) { 
					if (iframeid.contentDocument && iframeid.contentDocument.body.offsetHeight) { 
						iframeid.height = iframeid.contentDocument.body.offsetHeight; 
						} else if (iframeid.Document && iframeid.Document.body.scrollHeight) { 
							iframeid.height = iframeid.Document.body.scrollHeight; 
							} 
					} 
				} 
			} 
	</script> 
	
	<body>
		<div>
			<iframe id="top" name="top" src="Top.jsp" 
			scrolling="no" frameborder="no" allowtransparency="yes" border="0" marginwidth="0" marginheight="0" 
			width="100%" height="120">
			</iframe> 
		</div>
		<div>
			<iframe id="center" name="center" src="Center.jsp" 
			scrolling="no" frameborder="no" allowtransparency="yes" border="0" marginwidth="0" marginheight="0" 
			onload="Javascript:SetCwinHeight()"
			width="100%">
			</iframe> 
		</div>
		<div>
			<iframe id="down" name="down" src="Down.jsp" 
			scrolling="no" frameborder="no" allowtransparency="yes" border="0" marginwidth="0" marginheight="0" 
			width="100%" height="50">
			</iframe> 
		</div>
	</body>
	
</HTML>

 

 

posted @ 2010-06-14 14:46  zzdun  Views(4488)  Comments(0)    收藏  举报