Home  >  Article  >  Web Front-end  >  Using javascript to implement Iframe adaptive height_javascript skills

Using javascript to implement Iframe adaptive height_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:24:43976browse

Method 1:

Copy code The code is as follows:

$(window.parent.document).find("#ContentIframe").load(function() {
                    var main = $(window.parent.document).find("#ContentIframe");
                    var thisheight = $(document).height();
If (thisheight < 800)
Thisheight = 800;
                         main.height(thisheight);
                });

This way of writing can only adapt the height of the inherent element when loading. When the element changes (such as adding a lot of elements and the height changes), the iframe height of the parent form cannot be changed in time.

Method 2:

Copy code The code is as follows:

function setMainHeight() {

var main = $(window.parent.document).find("#ContentIframe");
var thisheight = $("body").height();
If (thisheight < 800) { thisheight = 800; }
Main.height(thisheight 50);
 
setTimeout(setMainHeight, 2000);
}

Add a timer to poll to determine the height change of the subpage.

Both of the above two can be iframes to achieve high adaptability. Friends, feel free to choose according to your own project needs

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn