滚动 Facebook 画布

发布于 2024-10-28 17:58:05 字数 450 浏览 1 评论 0原文

我正在构建一个 Facebook 应用程序。 Facebook画布类型是FBML,然后我将fb:iframe放入索引页面中,在该iframe中加载我的ajax引擎,之后,所有内容都通过ajax更新。有时内容页面可能很长并要求用户向下滚动(使用主浏览器滚动条)。但是,当您向下滚动后单击链接并加载下一个内容页面时,滚动条仍保持在原来的位置(这是有道理的),因此您必须滚动回顶部。

我通过在加载数据后强制滚动来解决这个问题。它确实到达了 div 的顶部,但没有到达页面的顶部,即 Facebook 栏所在的位置。我尝试滚动父窗口,但由于跨站点安全限制,这是不可能的。

我注意到,当您在加载内容的同一位置使用 FB.ui(即创建要发布的流)时,它会一直滚动到顶部。所以我想也许有一个 FB api 调用可以做到这一点,但我找不到它。

或者也许有某种方法可以强制浏览器一直向上滚动,无论您是否在 iframe 中?

有什么想法吗?

I'm building a Facebook app. Facebook canvas type is FBML, then I put the fb:iframe inside the index page, load my ajax engine inside of that iframe, and after that, all content is updated trhough ajax. Sometimes the content pages can be long and requre the user to scroll down (with the main browser scrollbar). But when you click a link after scrolling down and the next content page is loaded, the scrollbar remains where it was (which makes sense), so you have to scroll back to the top.

I managed to solve this by forcing a scroll after the data is loaded. And it does get to the top of the div, but not to the top of the page, where the facebook bar is. I tried scrolling the parent window but thats not possible due to cross-site security restrictions.

I noticed that when you use the FB.ui (ie. to create a stream to publish) from within the same place where I load my content, it does scroll all the way to the top. So I guess maybe there's a FB api call to do that, but I cant find it.

Or maybe some way to force the browser to scroll all the way up no matter if you're at an iframe?

Any ideas?

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

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

发布评论

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

评论(1

余生共白头 2024-11-04 17:58:05

2011 年 4 月更新:
Facebook 在其新的 JavaScript SDK 中添加了 FB.CanvasClient.scrollTo 方法。您现在所要做的就是:

FB.Canvas.scrollTo(0,0);

更多信息请参见:http://developers.facebook.com /docs/reference/javascript/FB.Canvas.scrollTo/


2011 年 4 月更新:以下内容现已过时,但我将其留在这里供参考...

使用新的 JavaScript SDK 还是旧的?对于旧版本,您可以执行以下操作:

FB.CanvasClient.scrollTo(0,0)

不幸的是,Facebook 不支持新 JavaScript API 的scrollTo() 方法。我还没有在 FBML 应用程序中尝试过下一种技术,但我确实在 Canvas iframe 应用程序中使用它取得了成功(从这里借用的代码:http://forum.developers.facebook.net/viewtopic.php?id=32906):

var x = 0, y = 0;
$("body").append('<iframe id="scrollTop" style="border:none;width:1px;height:1px;position:absolute;top:-10000px;left:-100px;" src="http://static.ak.facebook.com/xd_receiver_v0.4.php?r=1#%7B%22id%22%3A0%2C%22sc%22%3Anull%2C%22sf%22%3A%22%22%2C%22sr%22%3A2%2C%22h%22%3A%22iframeOuterServer%22%2C%22sid%22%3A%220.957%22%2C%22t%22%3A0%7D%5B0%2C%22iframeInnerClient%22%2C%22scrollTo%22%2C%7B%22x%22%3A' + x + '%2C%22y%22%3A' + y + '%7D%2Cfalse%5D" onload="$(\'#scrollTop\').remove();"></iframe>'); 

虽然上述技术会将窗口滚动到顶部,但我没有发现它100%可靠。例如,它似乎不适用于 Facebook 的新页面 iframe 选项卡。因此,我求助于使用这种 100% 可靠的技术,但不幸的是,它只会滚动到 iframe 的顶部:

将其放在开始标记的下方:

<a id="top" name="top" style="display:block;height:1px;width:1px;"></a>

以及将执行滚动的 JavaScript;

     window.location.hash = 'top';
     window.location.hash = '';

UPDATE April 2011:
Facebook added the FB.CanvasClient.scrollTo method to their new JavaScript SDK. All you have to do now is:

FB.Canvas.scrollTo(0,0);

More info here: http://developers.facebook.com/docs/reference/javascript/FB.Canvas.scrollTo/


UPDATE April 2011: The following content is now outdated, but I'm leaving it here for reference purposes...

Are you using the new JavaScript SDK or the old one? With the old one, you can do this:

FB.CanvasClient.scrollTo(0,0)

Unfortunately, Facebook doesn't support the scrollTo() method with the new JavaScript API. I haven't tried this next technique with an FBML app, but I did have success with it using it in a Canvas iframe app (code borrowed from here: http://forum.developers.facebook.net/viewtopic.php?id=32906):

var x = 0, y = 0;
$("body").append('<iframe id="scrollTop" style="border:none;width:1px;height:1px;position:absolute;top:-10000px;left:-100px;" src="http://static.ak.facebook.com/xd_receiver_v0.4.php?r=1#%7B%22id%22%3A0%2C%22sc%22%3Anull%2C%22sf%22%3A%22%22%2C%22sr%22%3A2%2C%22h%22%3A%22iframeOuterServer%22%2C%22sid%22%3A%220.957%22%2C%22t%22%3A0%7D%5B0%2C%22iframeInnerClient%22%2C%22scrollTo%22%2C%7B%22x%22%3A' + x + '%2C%22y%22%3A' + y + '%7D%2Cfalse%5D" onload="$(\'#scrollTop\').remove();"></iframe>'); 

While the above technique will scroll the window to the top, I didn't find it 100% reliable. For example, it doesn't seem to work in Facebook's new Page iframe tabs. So I've resorted to using this 100% reliable technique, but unfortunately, it will only scroll to the top of the iframe:

Place this just below your opening tag:

<a id="top" name="top" style="display:block;height:1px;width:1px;"></a>

And the JavaScript that will do the scrolling;

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