zoukankan      html  css  js  c++  java
  • iframe自适应高度的方法

    不带边框的iframe因为能和网页无缝的结合从而不刷新新页面的情况下实现更新页面部分的数据成为可能,可是iframe却不像层那样可以收缩自如,iframe高度需要动态的调整需要JS来配合使用,只能通过JS动态的来赋给他高度。

    function SetWinHeight(obj)
    {
      var win=obj;
      if (document.getElementById)
      {
        if (win && !window.opera)
        {
          if (win.contentDocument && win.contentDocument.body.offsetHeight)
            win.height = win.contentDocument.body.offsetHeight;
          else if(win.Document && win.Document.body.scrollHeight)
            win.height = win.Document.body.scrollHeight;
        }
      }

    }

    <iframe width="778" align="center" height="200" id="win" name="win" onload="Javascript:SetWinHeight(this)" frameborder="0" scrolling="no" src="1.htm"></iframe>

    或者:

    <script language="javascript" 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>
    <iframe src ="/default2.aspx" frameborder="0" marginheight="0" marginwidth="0" frameborder="0" scrolling="auto" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');" width="100%">
    </iframe>

  • 相关阅读:
    <<构建之法>>--第二次作业
    锁的内存语义
    MySQL触发器
    每天一个小示例 opencv(1)颜色直方图的统计 calcHist_Demo.cpp
    通过支持向量排名法来做行人鉴定
    数字信号处理101——DSP系统设计入门课程(1)
    matlab 与c++的混编
    FPGA图像处理之行缓存(linebuffer)的设计一
    基于FPGA的数字识别的实现
    使用matlab生成sine波mif文件
  • 原文地址:https://www.cnblogs.com/jsingleegg/p/3953628.html
Copyright © 2011-2022 走看看