zoukankan      html  css  js  c++  java
  • iframe根据子页面自动调整大小

    //iframe高度自适应

      function IFrameReSize(iframename) {

      var pTar = document.getElementById(iframename);

      if (pTar) { //ff

      if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {

      pTar.height = pTar.contentDocument.body.offsetHeight;

      } //ie

      else if (pTar.Document && pTar.Document.body.scrollHeight) {

      pTar.height = pTar.Document.body.scrollHeight;

      }

      }

      }

      //iframe宽度自适应

      function IFrameReSizeWidth(iframename) {

      var pTar = document.getElementById(iframename);

      if (pTar) { //ff

      if (pTar.contentDocument && pTar.contentDocument.body.offsetWidth) {

      pTar.width = pTar.contentDocument.body.offsetWidth;

      } //ie

      else if (pTar.Document && pTar.Document.body.scrollWidth) {

      pTar.width = pTar.Document.body.scrollWidth;

      }

      }

      }

      使用方法如下:

      <iframe src="Main.aspx" scrolling="no" frameborder="0" height="100%" id="mainFrame" width="100%" onload='IFrameReSize("mainFrame");IFrameReSizeWidth("mainFrame");'></iframe>

    复制代码

    佛为心,道为骨,儒为表,大度看世界; 技在手,能在身,思在脑,从容过生活; 三千年读史,不外功名利禄; 九万里悟道,终归诗酒田园;
  • 相关阅读:
    一个2核1G内存的服务器能做什么
    产品能力是一种底层能力
    利用容器逃逸实现远程登录k8s集群节点
    边缘计算k8s集群SuperEdge初体验
    LeetCode
    RSA加密
    RSA加密
    LeetCode
    LeetCode
    双端队列
  • 原文地址:https://www.cnblogs.com/taofx/p/4139402.html
Copyright © 2011-2022 走看看