如何使用iFrame重新加载滚动父页面 [英] How to scroll parent page with iFrame reload

查看:123
本文介绍了如何使用iFrame重新加载滚动父页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 loaded in the iframe?

这是页面

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

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>

谢谢!

推荐答案

你错过了<$ c的收盘 $ c> .ready()来电,你不应该在 body c>。

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

试试这个:

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.

这篇关于如何使用iFrame重新加载滚动父页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆