iframe 自适应高度(在父页面和在子页面调用的两个方法)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/HY_358116732/article/details/79021995

方法一:

在和iframe同一个页面中调用
 
 
$("#iframeId").load(function () {
var mainheight = $(this).contents().find("body").height() + 30;
$(this).height(mainheight);
});
方法二:
 
 
在iframe引用的子页面中调用
 
 
 
 
$(window.parent.document).find("#iframeId").load(function () {
var main = $(window.parent.document).find("#iframeId");
var thisheight = $(document).height() + 30;
main.height(thisheight);

});


猜你喜欢

转载自blog.csdn.net/HY_358116732/article/details/79021995