Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling scroll position for Facebook iFrame application's parent frame

I've got a Facebook iFrame application happily up and running, but I'm realizing 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!

like image 320
mikedory Avatar asked Feb 12 '10 17:02

mikedory


3 Answers

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/

like image 113
Johnny Oshika Avatar answered Sep 27 '22 20:09

Johnny Oshika


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>');
    }
like image 38
Rockurchin Avatar answered Sep 27 '22 19:09

Rockurchin


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.

like image 37
LocalPCGuy Avatar answered Sep 27 '22 19:09

LocalPCGuy