Home  >  Article  >  Web Front-end  >  jQuery simply implements the method of adapting the height of iframe according to the content of the page

jQuery simply implements the method of adapting the height of iframe according to the content of the page

高洛峰
高洛峰Original
2016-12-27 15:35:231183browse

The example of this article describes how jQuery simply implements the height of iframe to adapt according to the content of the page. Share it with everyone for your reference, as follows:

Method 1:

//注意:下面的代码是放在和iframe同一个页面中调用
$("#iframeId").load(function () {
    var mainheight = $(this).contents().find("body").height() + 30;
    $(this).height(mainheight);
});

Method 2:

//注意:下面的代码是放在iframe引用的子页面中调用
$(window.parent.document).find("#iframeId").load(function () {
    var main = $(window.parent.document).find("#iframeId");
    var thisheight = $(document).height() + 30;
    main.height(thisheight);
});

I hope this article will be helpful to everyone in jQuery programming.

For more jQuery-based methods to simply implement iframe height adaptation according to page content, please pay attention to the PHP Chinese website!

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