700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > layui实现iframe高度自适应

layui实现iframe高度自适应

时间:2022-10-25 09:18:36

相关推荐

layui实现iframe高度自适应

目录

ftl文件js文件

ftl文件

// A code block<div class="layui-tab-content"><div class="layui-tab-item layui-show "><iframe width=100% id="myiframe" onload="setHeight()" height="1" scrolling="no"frameborder="0" src=""></iframe></div></div>

js文件

js中写入

function getIframeWindow(obj) {return obj.contentWindow || obj.contentDocument.parentWindow;}function getIframeHeight(obj){var idoc = getIframeWindow(obj).document;if(idoc.body){return Math.max(idoc.body.scrollHeight,idoc.body.offsetHeight);}else if(idoc.documentElement){return Math.max(idoc.documentElement.scrollHeight,idoc.documentElement.offsetHeight);}}function setHeight(){var myiframe = document.getElementById("myiframe");myiframe.height = getIframeHeight(myiframe);}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。