Main.htm:
Copy codeThe Code is as follows:
<Html>
<Head>
<Meta http-equiv = 'content-type' Content = 'text/html; charset = gb2312 '>
<Meta name = 'author' content = 'F. R. Huang (meizz plum blossom snow) // www.meizz.com '>
<Title> iframe Adaptive Page height </title>
</Head>
<Body>
<Iframe src = "child.htm"> </iframe>
</Body>
</Html>
Child.htm:
<Html>
<Head>
<Meta http-equiv = 'content-type' Content = 'text/html; charset = gb2312 '>
<Meta name = 'author' content = 'F. R. Huang (meizz plum blossom snow) // www.meizz.com '>
<Title> iframe adaptive webpage loading (compatible with multiple browsers) </title>
<Script language = javascript>
Function iframeAutoFit ()
{
Try
{
If (window! = Parent)
{
Var a = parent.doc ument. getElementsByTagName ("IFRAME ");
For (var I = 0; I <a. length; I ++) // author: meizz
{
If (a [I]. contentWindow = window)
{
Var h = document. body. scrollHeight;
If (document. all) {h + = 4 ;}
If (window. opera) {h + = 1 ;}
A [I]. style. height = h;
}
}
}
}
Catch (ex)
{
Alert ("the script cannot perform cross-origin operations! ");
}
}
If (document. attachEvent) window. attachEvent ("onload", iframeAutoFit );
Else window. addEventListener ('load', iframeAutoFit, false );
</Script>
</Head>
<Body>
<Div style = "width: 200; height: 400; background-color: yellow">
Iframe adaptive webpage loading (compatible with multiple browsers)
</Div>
</Body>
</Html>