主页面:
先<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;">
解决方案 »
- if语句疑点
- jquery ajax 返回值
- 如何动态更换页面中的部分内容而不用刷新。
- 有没有办法在onbeforeunload里获取将要转向到的那个网址?
- 紧急:document.frmTest.selTest.options[1].selected=true;为什么不好使?
- IE6兼容问题
- easyui combobox 搜索速给接分 大侠们赶快来瞧瞧 作死的感觉
- 奇怪的DIV和TD块的自动折行问题,数字与字母竟然不同,有知道原因的吗?
- window.open
- 怎样让图层onmouseover平滑移动?
- 生成的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.调用的内容是不可控制的,是其他外在网站的网页。不过,无论怎么说,朋友们给的各种方法,都是在其他方面的很好的例子!!