Using javascript to implement Iframe adaptive height _ javascript skills

Source: Internet
Author: User
This article mainly introduces how to use javascript to implement Iframe adaptive height. If you need it, refer to method 1 below:

The Code is as follows:


Upload (w.w.parent.doc ument). find ("# ContentIframe"). load (function (){
Var main = Response (partition partition parent.doc ument). find ("# ContentIframe ");
Var thisheight = $ (document). height ();
If (thisheight <800)
Thisheight = 800;
Main. height (thisheight );
});

This method can only adapt to the height of inherent elements during loading. When elements change (for example, when many elements are added, the height changes), the iframe height of the parent form cannot be changed in time.

Method 2:

The Code is as follows:


Function setMainHeight (){

Var main = Response (partition partition parent.doc ument). find ("# ContentIframe ");
Var thisheight = $ ("body"). height ();
If (thisheight <800) {thisheight = 800 ;}
Main. height (thisheight + 50 );

SetTimeout (setMainHeight, 2000 );
}

Add a timer to poll and determine the height of the sub-page.

The above two types can be iframe for high self-adaptation. You can choose from them based on your project needs.

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.