vue下iframe怎么自适应高度

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue下iframe怎么自适应高度相关的知识,希望对你有一定的参考价值。

参考技术A 1.js代码设置

function setiframe(id)
var Iframe = document.getElementById(id);
try
// 声明变量取值
var bHeight = Iframe.contentWindow.document.body.scrollHeight;
var dHeight = Iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight); // 取最大值
Iframe.height = height;
catch (ex)


window.setInterval("setiframe('right_iframe')", 10); //0.01秒周期调用函数

2.对iframe进行设置:
<iframe name="right" id="right_iframe"
src="right.html" frameborder="false" scrolling="no" width="100%"
height="100%" allowtransparency="true"
onload="this.height=160" >
</iframe>本回答被提问者采纳

怎样让iframe中的内容的宽度和高度改变后,dialog的宽高自适应?

有一个dialog,里面有个iframe,
怎样让iframe中的内容的宽度和高度改变后,这个dialog的宽高自适应?

参考技术A

auto 

看你的dialog是怎么形成的?js,css还是什么、

追问

我子页面中只放了个div(宽500,高500)
var height = $(this).contents().find("body").height() + 50;
var width = $(this).contents().find("body").width() + 50;
$(this).height( height);
$(this).width(width);
jquery拿不到正确的宽高

追答

那应该是document的body的宽,高,如果是dom元素,就是那个dom元素的宽,高,你的contents是什么呀

以上是关于vue下iframe怎么自适应高度的主要内容,如果未能解决你的问题,请参考以下文章