Skip to content Skip to sidebar Skip to footer

How To Retain Scroll Position After Reloading The Web-page Too?

$(document).ready(function(){ $('#addmedic').click(function(){ sessionStorage.setItem('pos', $('div').scrollTop()); }); }); $(document).ready(fun

Solution 1:

You can use session storage to store the position then get back to the position when the page is reloaded, like this:

$(window).scroll(function() {
  sessionStorage.scrollTop = $(this).scrollTop();
});

$(document).ready(function() {
  if (sessionStorage.scrollTop != "undefined") {
    $(window).scrollTop(sessionStorage.scrollTop);
  }
});

Here is the JSFiddle demo

Solution 2:

Store scroll position in cookie before leaving page, then in case of page redirect use that cookie for setting the scroll position.

Post a Comment for "How To Retain Scroll Position After Reloading The Web-page Too?"