美文网首页
iframe高度自适应

iframe高度自适应

作者: 程序小小黑 | 来源:发表于2021-09-13 14:25 被阅读0次

<iframe
sandbox="allow-scripts allow-same-origin" //允许 iframe 内容被视为与包含文档有相同的来源。允许脚本执行。
data-alloy-tabstop="true"
tabindex="-1"
frameborder="0"
height="100%"
width="100%"
@load="iframeLoad"
:srcdoc="data"
ref="iframe"
></iframe>
</iframe>
<script type="text/javascript">
function iframeLoad(){
var iframe = document.getElementById("test");
try{
var iframe = this.$refs.iframe;
// iframe高度自适应
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height + 50;
}catch (ex){}
}
</script>

相关文章

网友评论

      本文标题:iframe高度自适应

      本文链接:https://www.haomeiwen.com/subject/cclfgltx.html