我在一个页面上有多个iframe。框架的来源是我自己的域。
我想计算和设置页面上所有iframe的iframe高度。

我的代码当前将所有iframe的高度从iframe之一设置为相同的高度:

function iframeSize(){

$("IFRAME_CLASS",parent.document).each(function() {
                var frameHeight = $("body").outerHeight();
                $(this).height(frameHeight);
            });

}


我遇到了很多麻烦,感谢您的帮助!

最佳答案

为了使用类IFRAME_CLASS遍历每个iframe,您需要在每个元素上执行class(.)选择器并设置高度。

function iframeSize(){

$(".IFRAME_CLASS").each(function() {
                var frameHeight = $("body").outerHeight();
                $(this).css("height",frameHeight);
 });

}
iframeSize();


示例:https://jsfiddle.net/DinoMyte/2ass96kf/3/

关于javascript - 根据内容高度为多个iFrame设置唯一的高度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34516251/

10-12 12:19
查看更多