Main.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 Page height </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 '/>
<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 type = "text/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 h1 = 0, h2 = 0;
A [I]. parentNode. style. height = a [I]. offsetHeight + "px ";
A [I]. style. height = "10px ";
If(document.documentElement&&document.doc umentElement. scrollHeight)
{
H1w.document.doc umentElement. 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: Adaptive webpage loading (compatible with multiple browsers and supports XHTML) </td>
</Tr>
</Table>
</Body>
</Html>
==============================================
How can I adapt the height of the iframe label to the src page?
For example: <iframe id = box2 name = "cok" src = "agree.htm" width = "100%" scrolling = "no" frameborder = "0" marginwidth = "0" marginheight = "0"> </iframe>
This iframe's height is 600 higher than agree.htm's height?
Don't tell me to set height = 600, because this iframe will apply several pages with different heights!
Thank you.
<Script>
Function autoResize ()
{
Try
{
Document. all ["test" cmd.style.height1_test.doc ument. body. scrollHeight
}
Catch (e ){}
}
</Script>
<Iframe id = test style = "height: expression (1); aho: expression (autoResize ()" src = "\"> </iframe>