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 的代码,是为了打开新的网页是,它去自适应高度和宽度。

 

posted @   周兴兴  阅读(162)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示