Prevent Refresh 'Jump' with Javascript

后端 未结 5 898
滥情空心
滥情空心 2021-02-05 17:20

I\'ve noticed that if you are on a page and you have scrolled down a good bit, if you refresh the page, most browsers will jump you back down to your position. Is there any way

5条回答
  •  佛祖请我去吃肉
    2021-02-05 17:49

    I see no reason why this shouldn't work in all browsers, seems to work for me (with only one function for window.onload, use more and there could be problems) ?

    window.onload = function() {
      scrollTo(0,0);
    }
    

    To make it work when back button is clicked aswell, maybe something like this:

    
    
    //content here
    
    

提交回复
热议问题