• 让iframe高度自适应


    总结两种方法。第一种是在网上查资料然后总结出来的,兼容性比較好,支持IE8,以及其它的标准浏览器。IE8下面版本号没有測试。IE8以上版本号基本都支持,这个方案是通过js来调整iframe的宽高的。另外一种方法非常easy。是我看朋友是这种写的,详细兼容性没有測试,应该不会差。不多少了,直接贴代码:

    第一种:

      <script type="text/javascript"> 
      function findDimensions(){  //函数:获取尺寸
      var winWidth = 0; 
    var winHeight = 0; 
    //获取窗体宽度 
    if (window.innerWidth){ 
    winWidth = window.innerWidth; 
    }else if ((document.body) && (document.body.clientWidth)){ 
    winWidth = document.body.clientWidth;
    }
    //获取窗体高度 
    if (window.innerHeight){  
    winHeight = window.innerHeight; 
    }else if ((document.body) && (document.body.clientHeight)){ 
    winHeight = document.body.clientHeight;
    }
    //通过深入Document内部对body进行检測,获取窗体大小 
    if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth){ 
    winHeight = document.documentElement.clientHeight; 
    winWidth = document.documentElement.clientWidth; 

    //调整div的高度以及iframe的宽高 
    var iframehei = winHeight - 180;
    var iframeWid = winWidth - 310;
    document.getElementById("Conframe").style.height=iframehei+"px";
    document.getElementById("Conframe").style.width=iframeWid+"px";

      
      $(document).ready(function(){
    findDimensions();
    menuOnClick("homePage/homePage.do"); 
    });
    //调用函数,获取数值 
    $(window).resize(function(){
    findDimensions();
    });
      </script>


    另外一种:

     <iframe name="main" src="home.jsp" width=100% onload="this.height=this.contentWindow.document.body.scrollHeight" frameborder=No border=0 marginwidth=0 marginheight=0 scrolling=no></iframe>(另外一种是不是非常easy?直接这样即可了
    onload="this.height=this.contentWindow.document.body.scrollHeight"


  • 相关阅读:
    SDN课程阅读作业(2)
    2019 SDN上机第4次作业
    第11组 Alpha事后诸葛亮
    第11组 Alpha冲刺(6/6)
    第11组 Alpha冲刺(5/6)
    2019 SDN上机第3次作业
    2019 SDN阅读作业
    第11组 Alpha冲刺(4/6)
    第11组 Alpha冲刺(3/6)
    模式识别和机器学习、数据挖掘的区别与联系(转发)
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/7065897.html
Copyright © 2020-2023  润新知