Iframe 自适应高度
网页中,经常遇见嵌套问题。我们怎么解决好点,我个人喜欢使用 Html 中的 Iframe 标签。忘记在哪里找的代码了。
Iframe 的代码:
<iframe src="indexpage.html" width="1030px" style="min-height:400px;_height:400px;" name="showInfo" frameborder="0" scrolling="no" id="iframeShow" onload="this.height=100"> </iframe>
在网页跳转中使用时,将 target="" ,改为 Iframe 的 name 属性值就可以了。
还需要 JavaScript 的代码辅助:
<script type="text/javascript"> //设置 iframe function reinitIframe() { var iframe = document.getElementById("iframeShow"); 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("reinitIframe()", 200); </script>
这个 JavaScript 的代码,是为了打开新的网页是,它去自适应高度和宽度。
作者:幸福摩天轮
------------------------------------------------
愿今日之努力日后想起还能浅浅一笑,不愿今日之颓废用长长一生去悔恨!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步