jQuery scroll to top of iframe parent

0 votes
asked Sep 27, 2010 by iltdev

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?

5 Answers

0 votes
answered Sep 27, 2010 by xar

Give a try for this one :

window.parent.$("body").animate({scrollTop:0}, 'slow');
0 votes
answered Sep 21, 2011 by angrej-singh
<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>
0 votes
answered Sep 7, 2012 by jeshurun

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.

0 votes
answered Jan 30, 2014 by steffanjj

Within the Iframe page.

window.parent.ScrollToTop(); // Scroll to top function

On The parrent page:

window.ScrollToTop = function(){
  $('html,body', window.document).animate({
    scrollTop: '0px'
  }, 'fast');
};
0 votes
answered Jan 20, 2016 by naveen-v

<body onLoad="window.parent.scroll(0,0);">

In the body of the iframe's html page

Its as simple as you can do!

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...