2

Let's just say I have a page that is quite long, like an article. There's a link like buy full article now or something. When clicked it will redirect to a page that contains all my script, add the article to the database, and redirect back again to the article page. Is this possible? and also, how can I make it that it will redirect to same scroll position that the user was browsing?

Good example of this is like the BACK button on the browser. It will take you to the previous page you visited, at the same scrolling position

Dranreb
  • 97
  • 2
  • 9

2 Answers2

1

From this question:

During page unload, get the scroll position and store it in local storage. Then during page load, check local storage and set that scroll position. Assuming you have a div element with id element. In case it's for the page, please change the selector :)

$(function() {
   $(window).unload(function() {
      var scrollPosition = $("div#element").scrollTop();
      localStorage.setItem("scrollPosition", scrollPosition);
   });
   if(localStorage.scrollPosition) {
      $("div#element").scrollTop(localStorage.getItem("scrollPosition"));
   }
});
Community
  • 1
  • 1
user82395214
  • 829
  • 14
  • 37
  • 2
    this will not work actually , if you go from page1 to page 2 it will save the scroll of page1, then if you go page from page2 to page1 it will save again the scroll amount of page 2 before going to page1 Final result : page 1 will scroll to the saved value from page2 – Jondi Sep 28 '17 at 03:49
-1

You can use Pure Javascript:

window.history.back()
allenski
  • 1,652
  • 4
  • 23
  • 39