1

I have a page which requires to reload on every 3 mint. My page is refreshing on every 3 mint but the problem is it resets the table scroll bar position too. I want my page should refresh an the scroll bar position will be at the same position before it was.

Like my table scroll bar is at the end.

enter image description here

But after refresh the scroll bar goes back to start position of the table.

enter image description here

I want my table scroll bar will remain in same position after reloading the page as it was before.

Community
  • 1
  • 1
Md . Sojib Ahmed
  • 431
  • 4
  • 14
  • is site include Jquery ? – Vo Kim Nguyen Nov 07 '19 at 07:27
  • Possible duplicate of [Refresh Page and Keep Scroll Position](https://stackoverflow.com/questions/17642872/refresh-page-and-keep-scroll-position) – Ogreucha Nov 07 '19 at 07:28
  • I think, you have to get the scrollbar position and set it to local or session storage , and once you back after reload, set those position back to scroll bar. for more help. https://stackoverflow.com/questions/2481350/how-to-get-scrollbar-position-with-javascript – Abhinav Kumar Nov 07 '19 at 07:28

1 Answers1

0

First, you have to take the value of the scroll that the table has before refreshing the page:

var scroll_value = $('.tableWithScroll').scrollLeft();

After refreshing the page, you should apply the scroll_value like this:

$(".tableWithScroll").scrollLeft(scroll_value);

Here on fiddle: https://jsfiddle.net/Samuel10F/aro390f6/61/

With this should be enough, the way to send the scroll_value after refreshing the page should be different depending on if you are doing some kind of POST or just using js. If you have questions about this you should share the code.

Samuel Diez
  • 541
  • 4
  • 5