• 中文
    • English
  • 注册
    • 查看作者
    • jQuery让父级iframe框架的高度自适应

      父级html代码里的iframe

      <!--内容显示-->
      <div style="padding:10px 0px;">
      	<iframe id="mainFrame" :src="activePath" width="100%" height="100%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes"></iframe>
      </div>

      方式一:

      //放在和iframe所在页面中调用
      $("#mainFrame").load(function () {
          var mainheight = $(this).contents().find("body").height() + 30;
          $(this).height(mainheight);
      });

      注意:没有设置元素高度的情况下,方式一可能不起作用,推荐使用方式二。

      方式二:

      //放在iframe引用的子页面中调用
      $(window.parent.document).find("#mainFrame").load(function () {
          var main = $(window.parent.document).find("#mainFrame");
          var thisheight = $(document).height() + 30;
          main.height(thisheight);
      });

    • 1
    • 0
    • 0
    • 159
    • 似水流年

      请登录之后再进行评论

      登录
    • 返回顶部
    • 做任务
    • 实时动态
    • 偏好设置
    • 到底部
    • 单栏布局 侧栏位置: