Take User Back to Where They Scrolled to on previous page when clicking Browser Back Button

后端 未结 6 1152
半阙折子戏
半阙折子戏 2020-12-05 01:14

Is it possible to take a user back to the area of a page where they scrolled down to when pressing the back button in a browser? As in --- pageA is double your screen size

6条回答
  •  囚心锁ツ
    2020-12-05 01:28

    You can use the following code to detect the scroll position.

     $(window).scroll(function (event){
        var scroll = $(window).scrollTop();
        // Do something
     });
    

    Then store scroll in a session and when you click back do scrollTop(scroll) .

提交回复
热议问题