Facebook IFrame 自动调整大小仍包括滚动条

发布于 2024-11-02 14:14:59 字数 528 浏览 1 评论 0原文

我已经尝试解决这个问题有一段时间了,但我没有运气。我有一个 Facebook 应用程序(witdh:510),它不断包含滚动条。这是它在 Facebook 上的样子: 带有白色滚动条的 Facebook 应用程序

我的应用程序中没有任何内容的宽度大于 510,所以我很困惑首先解释为什么会有空白。我也不明白为什么有一个垂直滚动条,因为页面上显然有足够的空间来容纳该应用程序。

在我的应用程序设置中,调用自动调整大小,并且我的 window.fbAsyncInit 函数中有 FB.Canvas.setAutoResize(); 。我还尝试使用 CSS Reset 但这并没有解决问题。

有什么建议吗?

I have been trying to fix this for a while but I have had no luck. I have a facebook app (witdh: 510) that keeps including scroll bars. This is how it looks in facebook:
Facebook App with white scroll bars

There is nothing in my application that will has a width greater then 510, so I am confused as to why there is white space in the first place. I also do not understand why there is a vertical scroll bar because there is clearly enough room on page to fit the app.

In my settings for the app Auto resize is called and I have FB.Canvas.setAutoResize(); in my window.fbAsyncInit function. I also tried using a CSS Reset <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.3.0/build/cssreset/reset-min.css"> but that did not clear the issue.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情泪▽动烟 2024-11-09 14:14:59

如果您确定 iFrame 的尺寸将始终显示内容,那么您只需设置:

<iframe src="yourpage.htm" scrolling="no"></iframe>

scrolling="no" 将强制 iFrame 不显示滚动条,即使内容大于框架。

这应该是不显示滚动条的可靠方法,但应谨慎使用,并且您应该知道,如果内容超出了 iFrame 的范围,则内容可能最终会被隐藏,而用户没有明显的方式滚动到它。

--edit--

由于您显然无法在 Facebook 上设置此设置,因此您应该简单地将正在加载的页面包装在包装器 div 中,并在那里设置高度、宽度和溢出属性。

<div class="wrap" style="height:500px;  width:510px;  overflow:hidden;">
  your page content here
</div>

您可以使用 overflow:hidden; 来表示没有滚动条,或者 overflow-x:hidden; 来仅隐藏水平滚动条,或者 overflow-y:hidden;< /em> 仅隐藏垂直滚动条。

If you are certain that the dimensions of your iFrame will always show the content, then you could just set:

<iframe src="yourpage.htm" scrolling="no"></iframe>

scrolling="no" will force the iFrame to NOT show scrollbars, even if content is bigger than the frame.

That should be a sure-fire way to NOT show scrollbars, but should be used cautiously and you should know that content may end up hidden with no apparent way for the user to scroll to it, if it extends beyond the bounds of the iFrame.

--edit--

Since you apparently can't set this on Facebook, you should simply wrap the page you're loading in a wrapper div and set the height, width, and overflow properties there.

<div class="wrap" style="height:500px;  width:510px;  overflow:hidden;">
  your page content here
</div>

You can use overflow:hidden; for no scrollbars, or overflow-x:hidden; for only hiding the horizontal scrollbar, or overflow-y:hidden; for only hiding the vertical scrollbar.

柏拉图鍀咏恒 2024-11-09 14:14:59

首先,我会使用“firebug”之类的内容检查我的 iframe HTML,检查所有 div 并验证 firebug 左侧的“布局”选项卡。您将看到元素的大小、边框、填充边距等,检查一切是否正确。

现在我有时遇到的情况是,facebook 的“自动调整大小”在某些浏览器上无法正常工作,因此它会错误计算高度,并且您的右侧仍然有一个滚动条,因此由于这个滚动条,您的内容变得太大,你还会得到一个水平滚动条。

我的解决方案是自己指定 iframe 的高度,而不是使用自动调整大小的东西,这里是执行此操作的代码(放在页面末尾的结束 之前) ) :

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {

    FB.init({appId: '{{fbapp_id}}', status: true, cookie: true,xfbml: true});

    window.setTimeout(function() {
        FB.Canvas.setSize({height:900});
    }, 250);

  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
</script>

这里我选择的高度是“900”,但你必须设置自己的高度(iframe 内容的高度 + 一些安全边距,如 50px 左右)

此外,你还必须替换 {{fbapp_id}} 通过您真实的 Facebook 应用程序 ID。

我希望这有帮助。

First I would inspect my iframe HTML with something like "firebug", you check all your divs and verify the "layout" tab on the left of firebug.. you will see the size of you element, your border, padding margin and so, check if everything is correct.

Now what happend to me some times is that the "auto resize" from facebook doesnt work correctly on some browsers, so it miscalculates the height, and you still have a scrollbar on the right side, so because of this scrollbar, your content becomes too large and you also get an horizontal scrollbar.

My solution to this was to specify the height of the iframe myself and not using the autoresize stuff, here is the code to do this (put at the end of your page before the closing </body>) :

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {

    FB.init({appId: '{{fbapp_id}}', status: true, cookie: true,xfbml: true});

    window.setTimeout(function() {
        FB.Canvas.setSize({height:900});
    }, 250);

  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
</script>

Here the height I choosed is "900" but you have to set your own height (the height of your iframe content + some security margin like 50px or so)

Also you have to replace {{fbapp_id}} by your real facebook application ID.

I hope this helps.

烟酒忠诚 2024-11-09 14:14:59

首先,删除填充和通过 css 与正文的边距

body {
 padding:0;
 margin:0;
}

将内容放在 div 中,将宽度设置为 520(如果仍然出现滚动条,则溢出:隐藏)。请注意此 DIV 上的填充和边框(请参阅 http://www.w3.org/ TR/CSS2/box.html 了解详细信息)

当您的内容很长时,设置此 div 的最小高度也很有帮助。有时你会得到垂直滚动条,这又会导致水平滚动条。

在页面的末尾,在关闭正文之前设置一个

FB.Canvas.setSize()

还要确保在您的应用程序设置中您有“自动高度”(或其调用方式)而不是滚动条。

first, remove padding & margin from the body via css

body {
 padding:0;
 margin:0;
}

have your content in a div which set the width to 520 (if you still get scrollbars, overflow:hidden). be carfull with padding and borders on this DIV (see http://www.w3.org/TR/CSS2/box.html for details)

when you have very long content, it also helps to set a min-height to this div. sometimes you get vertical scrollbars, which in turn leads to a horizontal scrollbar.

on the end of your page, right befor the closing body set a

FB.Canvas.setSize()

also make sure, in your app settings you have "automatic height" (or how its called) instead of scrollbars.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文