开发者

Controlling scroll position for Facebook iFrame application's parent frame

开发者 https://www.devze.com 2022-12-20 04:33 出处:网络
I\'ve got a Facebook iFrame application happily up and running, but I\'m real开发者_StackOverflowizing that I don\'t have a way to handle the scroll position of the parent frame because of cross-domai

I've got a Facebook iFrame application happily up and running, but I'm real开发者_StackOverflowizing that I don't have a way to handle the scroll position of the parent frame because of cross-domain issues. If a user clicks too far down on the page, I can't pop them back up to the top.

Has anyone had an luck with either any of the Facebook JS libraries or other JavaScript trickery to pull this off?

Thanks!


Facebook added the FB.Canvas.scrollTo method to the new JavaScript SDK on April 2011:

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


This works better for me (assumes use of Jquery)

$(document).ready(function($) {
        scrollTo(0,0);
    });

    function scrollTo(x,y){
        $("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>');
    }


The old library had some functions that worked, but they haven't been ported over to the new Javascript SDK library yet as of mid-June.

Added 10/12: Try using location.href("#top") to position the page as necessary. A little clunky, but better than nothing. You can position it anywhere you can put an ID or reference.

0

精彩评论

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