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

    方法一:

    <iframe src="http://www.fulibac.com" id="myiframe" scrolling="no" onload="changeFrameHeight()" frameborder="0"></iframe>

    js代码也得跟着改

    function changeFrameHeight(){
        var ifm= document.getElementById("iframepage"); 
        ifm.height=document.documentElement.clientHeight;

    }

    window.onresize=function(){  
         changeFrameHeight();  

    window.onresize的作用就是当窗口大小改变的时候会触发这个事件。

    方法二:

    <iframe src="需要连接的iframe地址" id="iframepage" name="iframepage" frameBorder=0 scrolling=no width="100%" onLoad="iFrameHeight()" ></iframe>
    js代码:
    <script type="text/javascript" language="javascript">
    function iFrameHeight() {
    var ifm= document.getElementById("iframepage");
    var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument;
    if(ifm != null && subWeb != null) {
    ifm.height = subWeb.body.scrollHeight;
    }
    }
    </script>
  • 相关阅读:
    使用PyDNS查询
    C#结构体
    使用CreateProcess函数运行其他程序
    运算符重载
    C#学习抽象类和方法
    sed命令使用
    Python For Delphi 示例
    建立Socket
    使用 lambda 函数
    C#接口实现
  • 原文地址:https://www.cnblogs.com/ch-zaizai/p/5962754.html
Copyright © 2011-2022 走看看