Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery scroll to top of iframe parent

Tags:

jquery

scroll

I have an iFrame with a feedback form in it. After the user clicks submit, I want use parent window to scroll to the top. I know I can scroll to the top of a page with:

$('html, body').animate({scrollTop:0}, 'slow');

However, this will only scroll the contents of the iframe, not the parent page. Any suggestions?

like image 448
iltdev Avatar asked Sep 27 '10 15:09

iltdev


3 Answers

Give a try for this one :

window.parent.$("body").animate({scrollTop:0}, 'slow');
like image 106
xar Avatar answered Nov 04 '22 20:11

xar


This seems to do the trick as well:

$('html, body', window.parent.document).animate({scrollTop:0}, 'slow');

The second parameter to $ is the context to search in.

like image 38
Jeshurun Avatar answered Nov 04 '22 20:11

Jeshurun


<script>
    jQuery(document).ready(function($) {
        FB.Canvas.scrollTo(0,0);
        FB.Canvas.setSize({width: 760, height:$('body').height()+20});
    });

    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#{%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}[0%2C%22iframeInnerClient%22%2C%22scrollTo%22%2C{%22x%22%3A'+x+'%2C%22y%22%3A'+y+'}%2Cfalse]" onload="$(\'#scrollTop\').remove();"></iframe>');
    }
</script>
like image 8
Angrej Singh Avatar answered Nov 04 '22 18:11

Angrej Singh