Prevent Refresh 'Jump' with Javascript

后端 未结 5 896
滥情空心
滥情空心 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 18:11

    Just to update what @josetapadas said, for recent versions it would be better to use the unload function instead of beforeunload this will be

    $(window).on('unload', function() {
    $(window).scrollTop(0);
    });
    

提交回复
热议问题