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

 

转载于:https://www.cnblogs.com/gzbit-zxx/p/7843195.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值