简体   繁体   English

如何为所有浏览器设置iFrame内容的高度?

[英]How can I set the height for iFrame content for all the browsers?

How can I set the height for iFrame content when content of the iframe is an asp.net site with master page ? 当iframe的内容是带有母版页的asp.net网站时,如何设置iFrame内容的高度?

Does anyone know any jQuery plug in ? 有谁知道任何jQuery插件?

Update This works fine in IE but fails in chrome and firefox 更新这在IE中工作正常但在chrome和firefox中失败

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

Calling it on body onload() 在body onload上调用它()

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

iframe code iframe代码

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

Script Works for all Browsers 脚本适用于所有浏览器

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM