【问题标题】:How to set dynamically the height of iFrame according to the website in jQuery如何在jQuery中根据网站动态设置iFrame的高度
【发布时间】:2012-02-29 09:16:18
【问题描述】:

任何解决方案?

我已经研究了许多解决方案,但没有奏效。

例如,我想加载 yahoo.com、cnet.com 等... 在这种情况下,我需要在 iFrame 中显示它们,但大小与在浏览器的单独窗口或选项卡中可以看到的大小相同。

终于找到了解决办法,大家分享一下。

<div id="frmLayout" style="position: absolute; top: 33px; left: 0; bottom: 0; right: 0;">
<iframe id="frm" style="position: absolute; width: 100%; height: 100%; overflow: auto; border: 0" src="http://news.yahoo.com/storms-kill-4-damage-branson-theater-district-    152532082.html"></iframe>
</div>    

【问题讨论】:

  • 我忘记注意到我的 iFrame 加载了另一个网站,如 google、yahoo 等。
  • 您好,欢迎来到 Stackoverflow。请查看faq 并使用更多信息更新您的问题。
  • 对应你的title你试过height="800"还是想动态改变你的iframe的高度?
  • 我已经发布了答案。不确定这是否有效,但如果有效,请回复
  • @Mojtaba 请重新表述您的问题。如果您遗漏了问题中的重要部分,难怪您会得到无用的解决方案。

标签: jquery iframe


【解决方案1】:

给你的 iframe 元素一个 id 或 class 属性,这样你就可以访问它,然后你应该能够通过执行以下操作使用 jQuery 更改高度:

$('#my_iframe').css('height', 800);

// or 

$('#my_iframe').height(800);

希望这有帮助吗?

【讨论】:

  • 根据我正在加载的网站动态。没用。
【解决方案2】:

用这个脚本检查这个网页:

这是一个可以帮助你的脚本。但我建议你去另一个方向。使用 iframe 并不总是一个好习惯。但如果没有其他办法,那就去吧;-)

【讨论】:

【解决方案3】:
<div id="frmLayout" style="position: absolute; top: 33px; left: 0; bottom: 0; right: 0;">
<iframe id="frm" style="position: absolute; width: 100%; height: 100%; overflow: auto;    border: 0" src="http://news.yahoo.com/storms-kill-4-damage-branson-theater-district-    152532082.html"></iframe>    
  </div>    

你可以尽可能用jquery改变位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-07
    • 1970-01-01
    • 2018-06-30
    • 2017-12-17
    • 2012-02-27
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    相关资源
    最近更新 更多