开发者

How to scroll parent page with iFrame reload

I have a page with a long iframe on it, which loads a schedule display with pages of various lengths. When a new page is displayed in the iframe though, the main page is often still showing the bottom of the page (lots of whitespace). How can I have the main page scroll to the top anytime a new page is loa开发者_如何学Cded in the iframe?

This is the page

I've tried this is jQuery (on the parent page):

<script type="text/javascript">
  jQuery(document).ready(function() {
    $('#body iframe').load(function(){
     $(window).scrollTop(0);
    });
  }
</script>

Thanks!


You're missing the closing ) for the .ready() call, and you shouldn't have a # before body.

Try this:

jQuery(document).ready(function() {
    $('body iframe').load(function(){
         $(window).scrollTop(0);
    });
});

With those corrections, the window jumps back to the top when the new content loads.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜