簡體   English   中英

如何為所有瀏覽器設置iFrame內容的高度?

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

當iframe的內容是帶有母版頁的asp.net網站時,如何設置iFrame內容的高度?

有誰知道任何jQuery插件?

更新這在IE中工作正常但在chrome和firefox中失敗

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

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

腳本適用於所有瀏覽器

<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