2009年4月21日

          iframe高度自動(dòng)調(diào)整(通過(guò)IE,firefox,opera測(cè)試)

          1.index.html
              <iframe id="mainIframe" scrolling="no" frameborder="0" width="100%" src="a.html"></iframe>
              <a href="#" onclick="page('a.html')">a頁(yè)面</a><a href="#" onclick="page('b.html')">b頁(yè)面</a>

          2 a.html  //內(nèi)嵌頁(yè)面
              <script language="javascript">
                    changeHight();
              </script>

          3. b.html  //內(nèi)嵌頁(yè)面
               <script language="javascript">
                    changeHight();
              </script>

          4. page.js
           function changeHight(){
            var iFrm = parent.document.getElementById("mainIframe");
               var subWeb = iFrm.contentDocument;
               if(subWeb){
              if (subWeb.body.scrollHeight>480)
             iFrm.height = subWeb.body.scrollHeight+20;
            else
                iFrm.height=500;
            } 
            if(top.document.frames["mainIframe"].document && window.document.body.scrollHeight!="0"){
             parent.document.getElementById("mainIframe").style.height=window.document.body.scrollHeight;
            }
            if(top.document.frames["mainIframe"].document && window.document.body.scrollHeight=="0"){
             parent.document.getElementById("mainIframe").style.height=500;
            }
          }

          function page(page){
              document.getElementById("mainIframe").src=page;
          }



          造成IE,FireFox,Opera中Iframe顯示差異原因在于
          1.iframe在FireFox中取法為parent.document.getElementById("mainIframe").contentDocument,而在ie,opera中為parent.document.getElementById("mainIframe").document
          2.當(dāng)頁(yè)面無(wú)滾動(dòng)時(shí),window.document.body.scrollHeight在IE中能取到,fireFox和Opera中取不到。

          posted @ 2009-04-21 14:05 software5168 閱讀(1290) | 評(píng)論 (0)編輯 收藏

          <2009年4月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          收藏夾

          JAVA學(xué)習(xí)網(wǎng)站

          綜合

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 龙江县| 秦安县| 清流县| 平乐县| 维西| 济宁市| 宁安市| 庆城县| 肇东市| 芒康县| 阜平县| 北安市| 通化市| 鄱阳县| 邵武市| 海丰县| 阿拉尔市| 香河县| 阳泉市| 江源县| 景谷| 延边| 固原市| 峨眉山市| 康定县| 旺苍县| 黄梅县| 建平县| 公主岭市| 正宁县| 内黄县| 岫岩| 株洲县| 杂多县| 永川市| 丰原市| 泰安市| 巫溪县| 宁强县| 新和县| 锡林郭勒盟|