Adaptive height framework-personal favorites

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.