Home >Web Front-end >JS Tutorial >jQuery simply implements the method of adapting the height of iframe according to the content of the page
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!