【问题标题】:Iframe autoresizeiframe 自动调整大小
【发布时间】:2013-06-19 17:15:24
【问题描述】:

我正在设计一个带有 HTML IFrame 的网页 有没有办法让 iframe 的宽度和高度自动调整大小,并且至少与 (IE,firefox,safari,chrom) 兼容??

请帮忙!

【问题讨论】:

标签: html iframe autoresize


【解决方案1】:

没有。

您可以很容易地管理宽度,但网页是流文档,并不“理解”高度的概念(至少不容易)。

为了做这样的事情,你必须使用 javascript。为了让您的 javascript 尽可能轻松地跨浏览器兼容,您应该使用诸如 jQuery 之类的框架。

这里有几个关于使用 jQuery like this one. 调整内容高度的问题

【讨论】:

    【解决方案2】:

    在 iframe 的 onload 中调用一个函数,您可以在其中设置 iframe 的高度、宽度。

    
    
        <iframe name="preview" id="preview" width="450" height="450"    onLoad="iframeResize();"></iframe>
    
        <script>
            function iframeResize () {
                document.getElementById('preview').height = SOMEVALUE
                document.getElementById('preview').width = SOMEVALUE
            }  
        </script>
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-27
      • 2011-04-26
      • 2021-06-30
      • 1970-01-01
      • 2014-03-19
      • 2020-12-27
      • 1970-01-01
      相关资源
      最近更新 更多