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>

  • 相关阅读:
    系统权限控制模型
    [Golang] 剑走偏锋 -- IoComplete ports
    Golang 正则匹配 -- regexp
    golang -- 字符串就地取反
    Hyperledger Fabric chaincode 开发(疑难解答)
    could not launch process: decoding dwarf section info at offset 0x0: too short
    win10 Ubuntu16 双系统
    7-8 哈利·波特的考试
    7-7 六度空间
    7-6 列出连通集
  • 原文地址:https://www.cnblogs.com/jsingleegg/p/3953628.html
Copyright © 2011-2022 走看看