• 解决iframe高度问题


    1

      function calcPageHeight(doc) {
        var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
        var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight)
        var height  = Math.max(cHeight, sHeight)
        var height1 = height+430
        return height1
    }
    //根据ID获取iframe对象
    var ifr = document.getElementById('mainFrame')
    ifr.onload = function() {
        //解决打开高度太高的页面后再打开高度较小页面滚动条不收缩,第一步置为绝对不能少,否则后面会一直保持一个高度
        ifr.style.height='0px';
        var iDoc = ifr.contentDocument || ifr.document
        var height = calcPageHeight(iDoc)
        ifr.style.height = height + 'px'
    } 

    2

    //函数形式
    function
    iframeH(){ //设置iframe高度 parent.document.getElementById("mainFrame").height=0+"px"; parent.document.getElementById("mainFrame").style.height = ""; var h = $(document.body).height() + 120; parent.document.getElementById("mainFrame").height = h; }

    //选择元素形式

    $(window.parent.document).find("#mainFrame").load(function () {
          if($(document).height()!=null&&$(document).height()!='0'){
              parent.document.getElementById("mainFrame").height=0+"px";
             parent.document.getElementById("mainFrame").style.height = "";
          parent.document.getElementById("mainFrame").height = $(document).height();
    }
    });

     
  • 相关阅读:
    怎样建设一个比较好的地方性商业门户网站
    地方门户网站如何推广
    【转】地方门户网站:地区细分领域的蓝海市场
    【转】测试人员可能会遇到的问题
    【转】工作反思-跳槽篇
    简单验证码识别 tessnet2
    log4net使用详解
    java理论基础学习三
    java理论基础学习二
    java理论基础学习一
  • 原文地址:https://www.cnblogs.com/zhoujingguoguo/p/9643034.html
Copyright © 2020-2023  润新知