javascript實現架構高度隨內容改變的方法,javascript實現架構

來源:互聯網
上載者:User

javascript實現架構高度隨內容改變的方法,javascript實現架構

本文執行個體講述了javascript實現架構高度隨內容改變的方法。分享給大家供大家參考。具體如下:

有兩種方法:

一、就是通過父頁面改變

這裡要理解架構的兩個屬性 contentWindow 和contentDocument 兩個屬性的意思和window document意思差不多,不同的是contentWindow 所有瀏覽器都支援,contentDocument   ie6,7不支援,chrome 也不支援

<iframe onload="change_height()"></iframe>function change_height(){  var iframe=document.getElementById("iframe_id");  //取得架構元素  var i_height=iframe.contentWindow.document.body.scrollHeight||iframe.contentWindow.document.documentElement.scrollHeight;  //取得架構內容的高度  iframe.height=i_height;  //改變}

二、就是通過內容改變

在內容頁進行

window.onload=function(){  var iframe=parent.document.getElementById("iframe_id");  //取得架構元素  iframe.height=document.body.scrollHeight||document.documentElement.scrollHeight;  //取得架構內容的高度並改變}

希望本文所述對大家的javascript程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.