主页面:
先<iframe id="frameName" src='aaa.htm'> </iframe>内嵌页:aaa.htm<body onload="parent.document.getElementById('frameName').height=document.body.scrollHeight;">
先<iframe id="frameName" src='aaa.htm'> </iframe>内嵌页:aaa.htm<body onload="parent.document.getElementById('frameName').height=document.body.scrollHeight;">
解决方案 »
- js如何控制object的swf文件
- 关于客户端写Cookies的问题
- 有个兼容性的问题,请高手解答,谢谢
- 关于scrollHeight和offsetHeight及scrollTop的问题(不兼容)
- 求救关于网页滚动条的特效
- JS 动态创建DIV(IE8没问题)Google chrome提示:Uncaught TypeError: Illegal invocation
- 学习百度api的问题
- 有人用javascript制作过站内搜索引擎吗?
- 最新ie版本(6.0.2800.1106)兼容性问题,请高手赐教!!
- 请教一个php、js的动态文章系统的方向问题
- 生成的cookie是保存在哪儿的?我在cookie文件夹中怎么找不到?
- 请各位推荐一个活跃的javaScript论坛
那就没有其它办法了吗?
谢谢fusoft在我上一个贴子中的回复!
document.getElementById('frameName').height=document.getElementById('frameName').scrollHeight;
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
//extra height in px to add to iframe in FireFox 1.0+ browsers
var FFextraHeight=getFFVersion>=0.1? 16 : 0 ;function dyniframesize(iframename)
{
var pTar = null;
if (document.getElementById)
{
pTar = document.getElementById(iframename);
}
else
{
eval('pTar = ' + iframename + ';');
}
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+FFextraHeight;
}
else if (pTar.Document && pTar.Document.body.scrollHeight)
{
//ie5+ syntax
pTar.height = pTar.Document.body.scrollHeight;
}
}
}
</script><iframe id="contentframe" border="0" name="content" frameSpacing="0" src="aaa.html"
scrolling="no" onload="javascript:{dyniframesize('contentframe');}" height="100%"
allowTransparency></iframe>
可惜老是生成页面错误,
ie6.0显示没有权限,还是调节不了!:(
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312' />
<title>iframe自适应加载的页面高度</title>
</head>
<body>
<div><iframe src="child.htm"></iframe></div>
</body>
</html>child.htm:<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312' />
<title>iframe 自适应其加载的网页(多浏览器兼容)</title>
<script type="text/javascript">
<!--
function iframeAutoFit()
{
try
{
if(window!=parent)
{
var a = parent.document.getElementsByTagName("IFRAME");
for(var i=0; i<a.length; i++)
{
if(a[i].contentWindow==window)
{
var h1=0, h2=0;
a[i].parentNode.style.height = a[i].offsetHeight +"px";
a[i].style.height = "10px";
if(document.documentElement&&document.documentElement.scrollHeight)
{
h1=document.documentElement.scrollHeight;
}
if(document.body) h2=document.body.scrollHeight; var h=Math.max(h1, h2);
if(document.all) {h += 4;}
if(window.opera) {h += 1;}
a[i].style.height = a[i].parentNode.style.height = h +"px";
}
}
}
}
catch (ex){}
}
if(window.attachEvent)
{
window.attachEvent("onload", iframeAutoFit);
//window.attachEvent("onresize", iframeAutoFit);
}
else if(window.addEventListener)
{
window.addEventListener('load', iframeAutoFit, false);
//window.addEventListener('resize', iframeAutoFit, false);
}
//-->
</script>
</head>
<body>
<table border="1" width="200" style="height: 400px; background-color: yellow">
<tr>
<td>iframe 自适应其加载的网页(多浏览器兼容,支持XHTML)</td>
</tr>
</table>
</body>
</html>
1.iframe根据调用内容不同自动适应高度
2.调用的内容是不可控制的,是其他外在网站的网页。不过,无论怎么说,朋友们给的各种方法,都是在其他方面的很好的例子!!