滚动 Facebook 画布
我正在构建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
2011 年 4 月更新:
Facebook 在其新的 JavaScript SDK 中添加了 FB.CanvasClient.scrollTo 方法。您现在所要做的就是:
更多信息请参见: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):
虽然上述技术会将窗口滚动到顶部,但我没有发现它100%可靠。例如,它似乎不适用于 Facebook 的新页面 iframe 选项卡。因此,我求助于使用这种 100% 可靠的技术,但不幸的是,它只会滚动到 iframe 的顶部:
将其放在开始标记的下方:
以及将执行滚动的 JavaScript;
UPDATE April 2011:
Facebook added the FB.CanvasClient.scrollTo method to their new JavaScript SDK. All you have to do now is:
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):
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:
And the JavaScript that will do the scrolling;