如何取得页面的高度? 1. 用 iframe 代替 frame 框架2. 让 iframe 的高度自适应里面加载的页面: 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如何让 iframe 的高度自适应里面加载的页面??谢谢梅花雪,请继续解答! <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> 谢谢,实现了我所想的,还有一个问题,这样不就是在每个iframe页面都要加载iframeAutoFit()函数iframe里的页面很多,每个都加是不是麻烦了点 你们都是高人哟你的代码我看了,也试了可以得到问题的效果。不过iframe 代替 frame 框架会不会使框架有问题给分吧!! 在线急救等下班捏···· 哪位高手能说下js作用域是怎么回事? 帮忙看个触发事件啊!!!!!! 如何清空文本域里的值? 如何解决文本框文字选择问题? 如何在框架中使用OPEN函数? 有没有人知道CSDN左侧的菜单用JAVASCRIPT如何实现 这个问题? 小问题,如何根据name或id得到其html标记类型? 大家好,请帮忙解决这样一个问题,就是关于弹出窗口的!!!!! 知道一个绝对地址和一个相对地址,怎么得到这个相对地址的绝对地址 form提交后怎么得到返回的xml文件
谢谢梅花雪,
请继续解答!
<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>
这样不就是在每个iframe页面都要加载iframeAutoFit()函数
iframe里的页面很多,每个都加是不是麻烦了点
你的代码我看了,也试了
可以得到问题的效果。
不过iframe 代替 frame 框架会不会使框架有问题
给分吧!!