Iframe 自适应高度宽度

来源:互联网 发布:管家婆进销存软件多少钱 编辑:程序博客网 时间:2024/04/20 15:43

方法一

----------------------------------------------------------------------------------------------------------------

 <html>
<head>
<title>page</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="css.css" rel="stylesheet" type="text/css">

<body bgcolor="#E2FEBC" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" load="changewin()">
   
 <iframe scrolling="no"  frameborder="0" height="" width="100%" src="Xml.mht" id="infobody" ></iframe>
       
</body>
</html>


<SCRIPT FOR=window EVENT=onload LANGUAGE="JScript">
//alert("onload");
changewin()
function changewin(){
if (infobody.document.body.scrollHeight){
   document.all("infobody").height=infobody.document.body.scrollHeight;
   }
   else
   {
   settimeout("changewin()",500);
   }
}

</SCRIPT>

 

方法2(另一哥们写的-xishanlang2001(西山狼2000)

------------------------------------------------------------------------------------------------------------------------

<html>
<script>
function test(the)
{
if( the.readyState == "complete" )
{
the.height = the.contentWindow.document.body.scrollHeight + 50 ;//ie6 only
/*ie5 user:*/
//window.frames[ the.id ].document.body.scrollHeight + 50 ;//ie6 only
}
}
</script>
<body>
<iframe id="aa" name="aa" src="2.htm" onreadystatechange="test(this)" ></iframe>
</body>
</html>