Loading IFRAME subpages in Javascript, adaptive height

Source: Internet
Author: User

Assume that there is a div on the home page, and an IFRAME is placed in it. CopyCode The Code is as follows: <Div id = "framebox">
<IFRAME id = "framewin" src = "1.html" name = "opwin" style = "width: 100%; height: 100% "frameborder =" 0 "scrolling =" no "> </iframe>
</Div>

The three menu links are loaded on the IFRAME.

The three subpages load window. onload on their own pages and executeCopy codeThe Code is as follows: function AA (){
VaR newheight = Document. Body. scrollheight + 20 + "PX ";
Optional bytes parent.doc ument. getelementbyid ("framebox"). style. Height = newheight;
// The above Firefox is passed, but IE6 must add the following sentence. Otherwise, the IFRAME height is changed, but the visible area is not changed.
Optional bytes parent.doc ument. getelementbyid ("framewin"). style. Height = newheight;
}

In the following method, you only need to put the code on the home page:
Page code:Copy codeThe Code is as follows: <Div style = "border: 1px solid #7e99c6" id = "framebox">
<IFRAME id = "framewin" src = "01.html" name = "opwin" style = "width: 100%; height: 100% "frameborder =" 0 "scrolling =" no "onLoad =" Test2 () "> </iframe>
</Div>

JS script (on the homepage ):Copy codeThe Code is as follows: function Test2 (){
VaR framewin = Document. getelementbyid ("framewin ");
VaR framebox = Document. getelementbyid ("framebox ");
VaR newheight;
If (framewin. Document ){
Newheight = framewin. Document. Body. scrollheight + 20 + "PX ";
} Else {
Newheight = framewin. contentdocument. Body. scrollheight + 20 + "PX ";
}
Framewin. style. Height = newheight;
Framebox. style. Height = newheight;
}

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.