Ifram架構適應高度 javascript實現

來源:互聯網
上載者:User

<script type="text/javascript">
        //架構自應用高度
        function dyniframesize(down) {
            var pTar = null;
            if (document.getElementById) {
                pTar = document.getElementById(down);
            }
            else {
                eval('pTar = ' + down + ';');
            }
            if (pTar && !window.opera) {
                //begin resizing iframe
                pTar.style.display = "block"
                if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
                    //ns6 syntax
                    pTar.height = pTar.contentDocument.body.offsetHeight + 20;
                    pTar.width = pTar.contentDocument.body.scrollWidth + 20;
                }
                else if (pTar.Document && pTar.Document.body.scrollHeight) {
                    //ie5+ syntax
                    pTar.height = pTar.Document.body.scrollHeight;
                    pTar.width = pTar.Document.body.scrollWidth;
                }
            }
        }        
    </script>

 

在Ifram處設定:

 <iframe style="vertical-align: top; padding-left: 0px; height: 447px; width:720px;
                                    background-color: #EAEEED" onload="javascript:dyniframesize('WorkSpace');" id="WorkSpace"
                                    marginwidth="0" scrolling="no" frameborder="0" name="ifram" src="CompanyManage.aspx">
</iframe>

上面這種方法我是在http://bbs.51aspx.com/showtopic-2263.html看來的,但是當你對這個ifram框進行設定了height時,那麼當你的內容超過height時就不能進行拉申了;

以下這種方法他不受你所設定的height的限制:

 <script type="text/javascript">

        if (window != top) top.location = window.location;
        // 調整 Table DesktopFrame 的大小,以使 IFrame WorkSpace 不出現捲軸
        function WorkSpaceLoad() {
            var h = WorkSpace.document.body.scrollHeight;
            if (h > 450)
                parent.DesktopFrame.height = h;
            parent.document.all.WorkSpace.style.height = h;

           
        }

</script>

在有架構的表格上設定:

<table width="100%" id="DesktopFrame">

 <tr>

<td>

<iframe style="vertical-align: top; padding-left: 0px; width: 725px;
                                    background-color: #EAEEED" id="WorkSpace"  onload="javascript:WorkSpaceLoad();"
                                    marginwidth="0" scrolling="no" frameborder="0" name="ifram" src="CompanyManage.aspx">
  </iframe>

</td>

</tr>

</table>

但是這兩種方法都受到了首次寬度的限制,就是說當你在同一個頁面時,有不同的操作,第一個操作顯示的內容少,第二個操作顯示的內容多;如果說你是先操作第一個,那麼當你操作第二個時頁面的架構是不會自動拉申的;此問題已經困了很久了,如有高手知道怎麼處理請分享一下,非常的感謝,,,,

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.