【问题标题】:How to make the iframe height dynamic according to the content and avoiding vertical scrolls in iframe?如何根据内容使iframe高度动态并避免iframe中的垂直滚动?
【发布时间】:2011-10-24 04:32:59
【问题描述】:

我试图搜索这个主题,但找不到任何合适的工作。各位大佬能推荐个方法吗? 我有一个需要显示 php 内容的 iframe。现在,有些php内容很短,有些很长,我希望我的iframe根据它包含的内容来获取高度。差不多就是这样。

【问题讨论】:

    标签: iframe dynamic height


    【解决方案1】:

    在 :

    中使用 Javascript
    <script>
      function DynamicIframe(obj) {
        obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
      }
    </script>
    

    像这样声明 iframe:

    <iframe src="..." frameborder="0" scrolling="no" onload="DynamicIframe(this)" />
    

    【讨论】:

      猜你喜欢
      • 2012-01-06
      • 2012-07-29
      • 2012-05-21
      • 2013-08-02
      • 1970-01-01
      • 2011-02-23
      • 2012-02-26
      • 2015-04-14
      • 2014-01-07
      相关资源
      最近更新 更多