<iframe width="100%" name="member_mainiframe" id="member_mainiframe" height="100" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" src="pm.php?job=list"></iframe><script type="text/javascript">
var dd= document.getElementById("member_mainiframe");
try{
var bHeight = dd.document.body.scrollHeight;
var dHeight = dd.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
dd.style.height = height;
}catch (ex){}
</script>IE8上可以了 但是FF不行的呢
var dd= document.getElementById("member_mainiframe");
try{
var bHeight = dd.document.body.scrollHeight;
var dHeight = dd.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
dd.style.height = height;
}catch (ex){}
</script>IE8上可以了 但是FF不行的呢
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>iframe自动适应页面的高度</title>
</head>
<style type="text/css">
*{font-family:verdana; font-size:12px;}
</style>
<script type="text/javascript"></script>
<body>
<p>iframe适应高度</p>
<p>1234</p>
<p>
<iframe id="iframe01" src="test.htm" frameborder="1" marginheight="0" marginwidth="0" width="100%" height="400"></iframe>
</body>
</html>iframe对应的也面 test.htm :<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<style type="text/css">
*{font-family:verdana; font-size:12px;}
.div01{border:1px solid red; padding:5px; background-color:#EEEEEE; font-family:verdana,arial; font-size:12px; display:none;}
</style>
<script type="text/javascript">
function resetHeight(){
//调整父窗口的iframe高度
var subPageHeight=document.body.scrollHeight || document.document.documentElement.scrollHeight;
parent.document.getElementById("iframe01").height=subPageHeight+30;
}
</script>
<body onLoad="javascript:resetHeight();">
<p></p>
<div id="msgTip" class="div01"></div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p><p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>
function resetHeight(){
//调整父窗口的iframe高度
var subPageHeight=document.body.scrollHeight || document.document.documentElement.scrollHeight;
alert(subPageHeight);
parent.document.getElementById("member_mainiframe").height=subPageHeight+30; 这个 怎么没有变化的呢
}
</script>
<body onLoad="javascript:resetHeight();"><div id="append"></div><iframe width="100%" name="member_mainiframe" id="member_mainiframe" height="100" scrolling="no" marginwidth=0 marginheight=0 frameborder="0" src=""></iframe>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title>a</title>
</head>
<body>
<div style="border:1px dotted;width:400px">
<iframe id="frame_content" src="iframe_b.html" scrolling="no" frameborder="0" onload="this.height=100"></iframe>
</div>
<div><button onclick="checkHeight()">Check Height</button></div>
<script type="text/javascript">
function reinitIframe(){
var iframe = document.getElementById("frame_content");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight); //max()
iframe.height = height;
}catch (ex){}
}
window.setInterval("reinitIframe()", 200);
function checkHeight() {
var iframe = document.getElementById("frame_content");
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
alert("bHeight:" + bHeight + ", dHeight:" + dHeight);
}
</script>
</body>
</html> 试试这个 主要是max起作用 setInterval也没占用多少资源 可以忽略不计!
var pTar = null;
if ($){
pTar = $(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;
}
else if (pTar.Document && pTar.Document.body.scrollHeight){
//ie5+ syntax
pTar.height = pTar.Document.body.scrollHeight;
//pTar.width = pTar.Document.body.scrollWidth;
}
}
}
如何是在同域名的话是可以的,但我这个是调用另外个域名页面的 就不行了啊。
contentWindow 是不能跨域的!
function SetCwinHeight(obj)
{
var cwin=obj;
if (document.getElementById)
{
if (cwin && !window.opera)
{
if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
cwin.height = cwin.contentDocument.body.offsetHeight + 40; //FF NS
else if(cwin.Document && cwin.Document.body.scrollHeight)
cwin.height = cwin.Document.body.scrollHeight + 40;//IE
}
else
{
if(cwin.contentWindow.document && cwin.contentWindow.document.body.scrollHeight)
cwin.height = cwin.contentWindow.document.body.scrollHeight;//Opera
}
}
}