Puksmyz Posted February 26 Share Posted February 26 I saw a lot of people has encountered this problem, so let's break it down for the last time so that everybody will save a lot of time. I have a code that makes you go back to your last scroll point when using browsers back button, but when entering a page it just randomly takes you to the bottom of it, chatgpt is useless for this, would be a lifesaver if somebody would help with it. Here's the code: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { if (localStorage.getItem("my_app_name_here-quote-scroll") != null) { $(window).scrollTop(localStorage.getItem("my_app_name_here-quote-scroll")); } $(window).on("scroll", function() { localStorage.setItem("my_app_name_here-quote-scroll", $(window).scrollTop()); }); }); </script> Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment