iframe 自动延伸的几种方法尝试

主界面and 几种js方法:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.left{width:200px;height:500px; background:#9FC; float:left;}
.right{width:400px;-height:600px; -background:#0F3; float:left;}
</style>
<script src="jquery-1.8.2.min.js"></script>
<script>
/*function SetWinHeight(obj) { 
	var win=obj; 
	if (document.getElementById) { 
		if (win && !window.opera) { 
			if (win.contentDocument && win.contentDocument.body.offsetHeight) 
				win.height = win.contentDocument.body.offsetHeight; 
			else if(win.Document && win.Document.body.scrollHeight) 
				win.height = win.Document.body.scrollHeight; 
		} 
	} 
} */
/*function iFrameHeight() { 
	var ifm= document.getElementById("iframepage"); 
	var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument; 
	if(ifm != null && subWeb != null) { 
		ifm.height = subWeb.body.scrollHeight; 
	} 
} */


/*
function dyniframesize(down) { 
	var pTar = null; 
	if (document.getElementById){ 
		pTar = document.getElementById(down); 
	} 
	else{ 
		eval('pTar = ' + down + ';'); 
	} 
	if (pTar && !window.opera){ 
		//begin resizing iframe 
		pTar.style.display="block" 
		if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){ 
			//ns6 syntax 
			pTar.height = pTar.contentDocument.body.offsetHeight +20; 
			pTar.width = pTar.contentDocument.body.scrollWidth+20; 
		} 
		else if (pTar.Document && pTar.Document.body.scrollHeight){ 
			//ie5+ syntax 
			pTar.height = pTar.Document.body.scrollHeight; 
			pTar.width = pTar.Document.body.scrollWidth; 
		} 
	} 
} */
function SetCwinHeight() { 
	var iframeid = document.getElementById("maincontent1"); //iframe id 
	iframeid.height = "10px";//先给一个够小的初值,然后再长高. 
	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>
</head>

<body>
<div>
	<div class="left"></div>
    <div class="right">
    	<!-- 
    	<iframe src="2.html" width=100% align="center"  id="win" name="win" οnlοad="Javascript:SetWinHeight(this)" frameborder="0" scrolling="no" ></iframe>
        
        <iframe src="2.html" id="iframepage" name="iframepage" frameBorder=0 scrolling=no width="100%" onLoad="iFrameHeight()" ></iframe>
       
        <iframe src="2.html" frameborder="0" marginheight="0" marginwidth="0" frameborder="0" scrolling="auto" id="ifm" name="ifm" οnlοad="javascript:dyniframesize('ifm');" width="100%">
</iframe>
	 -->
     <iframe style="z-index: 1; visibility: inherit; width: 100%;" name="maincontent1" 
οnlοad="Javascript:SetCwinHeight()" height="1" id="maincontent1" src="2.html" 
marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe> 
    </div>
</div>
</body>
</html>

子界面就是赋值了一个高:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{width:100%;height:1500px; background:#9F0;}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>

经过测试可以使用,不过没有测试所有的浏览器就试了ie

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值