【问题标题】:How to change IFrame height to 100% of its content?如何将 IFrame 高度更改为其内容的 100%?
【发布时间】:2017-04-16 14:15:41
【问题描述】:

我尝试将 IFrame 高度设置为 100%(例如 <div>height:auto)。

我将<iframe> 标记中的height 属性设置为100%,并将样式中的height 也设置为100%,但它似乎不起作用。

然后,我尝试使用JavaScript和JQuery来获取<iframe>内容的高度,但是由于浏览器安全原因,没有获取到height的内容

我该如何解决这个问题?我花了一整天的时间来解决这个问题。

【问题讨论】:

  • 你的代码,让我们知道错误?
  • 您的iframe 是否包含任何跨域内容?
  • @DanPhilip 是的,它适用于不同的域
  • @IshanMahajan $("#IframeId").load(function() { $(this).height( $(this).contents().find("body").height() ); }); 错误:访问属性“文档”的权限被拒绝

标签: javascript jquery html css iframe


【解决方案1】:

iFrame 属性在 HTML5 中不支持百分比。它只支持像素。 所以你的问题是用像素值解决的。

How do you give iframe 100% height

http://www.w3schools.com/tags/att_iframe_height.asp

【讨论】:

    猜你喜欢
    • 2022-06-21
    • 2016-06-17
    • 2013-03-06
    • 2014-12-25
    • 1970-01-01
    • 2022-12-16
    • 2013-05-19
    • 2012-01-06
    • 2014-11-06
    相关资源
    最近更新 更多