【问题标题】:Adjust Iframe height调整 iframe 高度
【发布时间】:2013-04-19 20:42:56
【问题描述】:

是否有任何方法可用于动态调整 iframe(加载外部网站)的高度?

有没有办法检查 iframe 是否有滚动条?

【问题讨论】:

  • 我相信这个stackoverflow.com/questions/819416/…就是你要找的东西
  • 是的,但没有什么对我有用。我正在尝试从外部站点加载文档:(
  • 由于当 iframe 来自另一个域时您无法访问任何内容,这仅在远程站点“帮助”您时才有效——就像 Facebook 为画布/页面选项卡应用程序所做的那样,他们做了一些跨域通信,以便 iframed 页面将自己的高度发送给父级。

标签: javascript jquery html iframe


【解决方案1】:

试试这个:

// Get the iFrame jQuery Object
var $MyFrame = $("#iframeid");

// You need to wait for the iFrame content to load first
// So, that the click events work properly
$MyFrame.load(function () {
    var frameBody = $MyFrame.contents().find('body');

    // Set the iFrame height
    $MyFrame.css({
        height: frameBody.outerHeight()
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-06
    • 2011-08-23
    • 1970-01-01
    • 1970-01-01
    • 2014-11-06
    • 2018-03-23
    • 2013-10-28
    • 2011-11-25
    相关资源
    最近更新 更多