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

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

高洛峰
Release: 2016-12-27 15:35:23
Original
1227 people have browsed it

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);
});
Copy after login

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);
});
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!