zoukankan      html  css  js  c++  java
  • 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 的代码,是为了打开新的网页是,它去自适应高度和宽度。

  • 相关阅读:
    mouseenter和mouseleave,mouseover和mouseout
    哈哈哈
    instanceof与typeof
    js事件传参
    浮动与清除问题
    简易富文本编辑
    js之prototype
    json序列化
    我对Defer and Promise的实现
    Ajax 完整教程
  • 原文地址:https://www.cnblogs.com/gzbit-zxx/p/7843195.html
Copyright © 2011-2022 走看看