问个问题,关于判断iframe里面页面的高度
有一iframe在页面a中
iframe的src是另一个页面b
为了让iframe不出现滚动条
我需要在a页面中根据b页面的高度和宽度动态设置iframe的高度和宽度
问题在于
我需要如何去取得b页面的高度和宽度?
不吝赐教,万分感激!
问题点数:100、回复次数:6Top
1 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2006-02-24 17:19:09 得分 100
如果何能使iframe的大小随着它包含的网页里面的table大小变化而变化?急切!!!
A :
例如,怎样使iframe的高度和宽度 随着table的高度和宽度 改变而改变?如下:
Main.htm
<html>
<body>
<div>
<iframe name=mm src=”detail.htm” width=”变数” height=”变数” </iframe>
</div>
</body>
</html>
detail.htm
<html>
<body>
<table width=”变数” height=”变数” border=0 bgcolor=red>
<tr><td></td></tr>
</table>
</body>
</html>
急切,请高手快指点!!!!
---------------------------------------------------------------
main.htm
<html>
<body>
<div>
<iframe id=frmDetail scrolling=no name=mm src="detail.htm" style="width:expression(this.contentWindow.document.all.tblDetail.width);height:expression(this.contentWindow.document.all.tblDetail.height)"></iframe>
<button onclick="with(document.all.frmDetail.contentWindow.document.all.tblDetail){width=offsetWidth+1}">+</button>
<button onclick="with(document.all.frmDetail.contentWindow.document.all.tblDetail){width=offsetWidth-1}">-</button>
</div>
</body>
</html>
detail.htm
<html>
<body leftmargin=0 topmargin=0>
<table id=tblDetail width=100 height=100 border=0 bgcolor=red>
<tr><td></td></tr>
</table>
</body>
</html>
---------------------------------------------------------------
稍微变通一下就是啦.
main.htm
<html>
<body>
<div>
<iframe id=frmDetail scrolling=no name=mm src="tb.htm" onload="style.width=this.contentWindow.document.all.tblDetail.offsetWidth;style.height=this.contentWindow.document.all.tblDetail.offsetHeight"></iframe>
</div>
</body>
</html>
tb.htm
<html>
<body leftmargin=0 topmargin=0>
<table id=tblDetail width=100 height=100 border=0 bgcolor=red>
<tr><td>
dddddddddddddddddddddddddddddddddddddddddddddddddddddddd
</td></tr>
</table>
</body>
</html>
---------------------------------------------------------------
test.asp
<%
url=Request.QueryString("url")
%>
<body onload="document.all.ifId.style.width=parseInt(ifId.document.getElementsByTagName('table')[0].width)+20">
<iframe name=ifId id=ifId src="<%=url%>"></iframe>
<br>
<a href=2.asp?url=1.asp>1.asp</a>
<br>
<a href=2.asp?url=2.asp>2.asp</a>
1.asp
<table width=500>
<tr><td>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</table>
2.asp
<table width=200>
<tr><td>
aaaaaaaaa
</table>Top
2 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2006-02-24 17:19:47 得分 0
如何更改<iframe>的高度?急!在线等,高分!
A :
有这样的代码:
<iframe frameborder="0" scrolling="no" src="body.htm" width="778" height="710" name="m_body"></iframe>
如何在body.htm里改变<iframe>的高度!
---------------------------------------------------------------
<body onload="parent.document.all.m_body.style.height='4000'">Top
3 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2006-02-24 17:20:21 得分 0
如何在iframe的name不定时,根据被包含页面大小动态改变iframe的大小?
A :
秋水无痕:
<script language="javascript">
function toppage()
{
if (self.location!=top.location)frameElement.height=document.body.scrollHeight + 30;
}
</script>
<body onload="toppage()">
frameElement地用法,可见
http://www.blueidea.com/bbs/newsdetail.asp?id=442170
但frameElement只有在IE5.5以上支持。
根据秋水的提示,我在看了
http://www.blueidea.com/bbs/newsdetail.asp?id=340771
后知道了完美的解决办法。
<script language="javascript">
<!--
function toppage()
{
if (self.location!=top.location)
{
parent.document.all(self.name).height=document.body.scrollHeight + 30;
}
}
-->
</script>
<body onload="toppage()">
IE5.0测试通过,IE4没法试了,不过还用IE4的非常少了,基本可以不考虑。Top
4 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2006-02-24 17:20:43 得分 0
Iframe 自适应其加载的网页高度(多浏览器兼容版)
A :
如何在打开这个页面时得到这个页面的高度?
一个框架面面,包含三个页面
头,左,右三个页面
右面的页面是主显示区会有滚动条,如何让整个框架页有滚动条,而不是单个页面出滚动条。
---------------------------------------------------------------
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'>
<title>用 iframe 模拟 frame 使网架网页能够居中</title>
</head>
<body topmargin=0 leftmargin=0><center>
<table border=0 width=780 height=100% cellspacing=0 cellpadding=0 align=center>
<tr><td width=780 colspan=2 height=100>
<iframe width=100% height=100% frameborder=1></iframe>
</td></tr>
<tr>
<td width=180>
<iframe width=100% height=100% frameborder=1></iframe>
</td>
<td width=600 valign=top><div style="height: 100%">
<iframe width=100% height=100% name="MzMain" frameborder=1
id="MzMain" src="用iframe模拟frame子页.htm"></iframe>
</div></td>
</tr>
</table>
</center></body></html>
用iframe模拟frame子页.htm
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='F.R.Huang(meizz梅花雪)//www.meizz.com'>
<title>iframe 自适应其加载的网页(多浏览器兼容)</title>
<script language=javascript>
function iframeAutoFit() //author: meizz(梅花雪 20041225)
{
if(self!=top && window.name=="MzMain") //这个 name 对应的是 iframe 的 name
{
var iframe = parent.document.getElementById(window.name);
if(iframe)
{
iframe.parentNode.style.height = iframe.style.height;
iframe.style.height = 10;
var h = document.body.scrollHeight;
var minimalHeight = parseInt((window.screen.width*11)/16, 10) - 280;
h = h<minimalHeight ? minimalHeight : h;
if(window.navigator.appName == "Microsoft Internet Explorer"
&& iframe.frameBorder=="1") h += 4;
iframe.parentNode.style.height = iframe.style.height = h;
}
else alert("Iframe's id unequal to iframe's name!");
}
}
if(document.attachEvent) window.attachEvent("onload", iframeAutoFit);
else window.addEventListener('load', iframeAutoFit, false);
</script>
</head>
<body>
<span style="width: 300; height: 400; background-color: yellow">
iframe 自适应其加载的网页(多浏览器兼容)
</span>
</body>
</html>Top
5 楼ForMyBrian(人~~)回复于 2006-02-24 17:22:58 得分 0
顿首
谢Top
6 楼ice_berg16(寻梦的稻草人)回复于 2006-02-24 17:24:29 得分 0
在iframe页内
window.onload =function(){
parent.document.getElementById("iframeID").width=document.body.scrollHeight;
}Top




