如何使用iFrame重新加载滚动父页面

时间:2010-11-08 02:09:06

标签: jquery iframe scroll

我有一个带有长iframe的页面,它会加载包含各种长度页面的计划显示。当iframe中显示新页面时,主页面通常仍显示页面底部(大量空格)。如果在iframe中加载新页面,我怎样才能将主页面滚动到顶部?

This is the page

我试过这是jQuery(在父页面上):

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

谢谢!

1 个答案:

答案 0 :(得分:7)

您错过了)来电的结束.ready(),而#之前不应该有body

试试这个:

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

通过这些更正,当新内容加载时,窗口会跳回到顶部。

相关问题