开发者

Facebook Canvas IFRAME needs to get ScrollTop() value of parent page

I'll state right away I know this isn't possible due to security restrictions, but here's my scenario and I'm looking for some creative workarounds that I may not have considered.

I have a web site that displays thumbnails of images. When users click on the thumbnails, I use a jQuery overlay control (FaceBox) to display the full-sized image in a popup. The top of the popup window is always positioned 20 pixels from the top of the page, so it needs to read the scrollTop() value of the page.

This feature works great when I access my site directly. But when I load the site from a Faceboo开发者_Python百科k Canvas Application in an IFRAME, my positioning code for the popup breaks. I have turned off scroll bars for the Canvas and am using FB.Canvas.setSize(...) to manually notify the parent page of height changes in my IFRAME. Since I'm not allowed to access the ScrollTop() value in the parent, my workaround has been to position the top of the overlay relative to the top of the source thumbnail. This keeps the overlay close to the source, but it's hardly ideal, especially if the thumbnail is close to the bottom of the viewport.

Is there any way that I can position the popup 20 pixels from the top of the IFRAME but somehow take into account the (forbidden) ScrollTop() location of the parent window?

This seems like a fairly common scenario; I hope that Facebook has plans to address this in the future. The FB.Canvas.getPageInfo object looks like a good candidate for this. It has a scrollTop member, but it's for the Canvas, not the parent frame, and if scroll bars are turned off, this value is always zero.


So, it turns out that the native FB.Canvas.getPageInfo() method does exactly what I wanted it to do all along. I added some code to secretly invoke this from within my Facebook app (http://apps.facebook.com/ipredikt) and it returned the values I need to properly position popups and overlays. The next time we push new bits to Azure, I'll update my positioning code to take into account value from FB.Canvas.getPageInfo().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜