How to scroll parent page with iFrame reload

让人想犯罪 __ 提交于 2020-01-03 17:05:55

问题


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?

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!


回答1:


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.



来源:https://stackoverflow.com/questions/4120813/how-to-scroll-parent-page-with-iframe-reload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!