【问题标题】:How can I set the height for iFrame content for all the browsers?如何为所有浏览器设置 iFrame 内容的高度?
【发布时间】:2023-04-01 14:19:01
【问题描述】:

当 iframe 的内容是带有母版页的 asp.net 站点时,如何设置 iFrame 内容的高度?

有谁知道jQuery插件吗?

更新 这在 IE 中运行良好,但在 chrome 和 firefox 中失败

    function resizeFrame(f) {
        f.style.height = f.contentWindow.document.body.scrollHeight + "px";
    }

在正文 onload() 上调用它

body onload="resizeFrame(document.getElementById('MainIFrame'))"

iframe 代码

        <iframe id="MainIFrame" class="autoHeight" runat="server" marginwidth="0"    style="margin: auto; " 
                frameborder="0" width="100%" scrolling="no" >
                </iframe>

【问题讨论】:

标签: javascript jquery asp.net iframe


【解决方案1】:

脚本适用于所有浏览器

<script type="text/javascript" language="javascript">
        function resizeIframe(dynheight) {
            try {
                var f = document.getElementById("autosizeframe");
                document.getElementById("autosizeframe").height = parseInt(dynheight) + 10;
                if (f.contentDocument) {
                    f.height = f.contentDocument.documentElement.scrollHeight + 30; //FF 3.0.11, Opera 9.63, and Chrome
                } else {
                    f.height = f.contentWindow.document.body.scrollHeight + 30; //IE6, IE7 and Chrome

                }
            }

            catch (err) {
                alert('Err: ' + err.message);
                window.status = err.message;
            }
        }

        window.onload = function() {
            var height = document.body.scrollHeight;
            resizeIframe(height);

        };                                

    </script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    相关资源
    最近更新 更多