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.