Home > Web Front-end > JS Tutorial > body text

Using javascript to implement Iframe adaptive height_javascript skills

WBOY
Release: 2016-05-16 16:24:43
Original
975 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template