CptFeeny Posted September 5, 2023 Share Posted September 5, 2023 (edited) I need help returning to the same place on the previous page for the mobile version of my website. • Attached is a screen recording of my mobile site where I demonstrate scrolling down a store page to a product page, accessing the product page, and then returning to the store page. • Also attached is a screen recording of my desktop site where I demonstrate the same sequence as in the mobile version. As you can see, the mobile version returns to the top of the page whereas the desktop version returns to the previous position. I would like the mobile version to return to the previous position just like the desktop version. Any help is greatly appreciated! 😃 Website: https://www.brendanalexphoenix.com/prints-oregon Mobile_Previous page position not working_Demo.mp4 Desktop_Previous page position working_Demo.mp4 Edited September 5, 2023 by CptFeeny Added website URL Link to comment
tuanphan Posted September 9, 2023 Share Posted September 9, 2023 Hi, Have you found a solution yet? Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!) Link to comment
CptFeeny Posted September 19, 2023 Author Share Posted September 19, 2023 On 9/9/2023 at 2:36 AM, tuanphan said: Hi, Have you found a solution yet? I still need help. You shared code with me in another post but it didn't work. <!-- by @nhannhot-tuanphan --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script> <script> $(document).ready(() => { function scrollToAnchor(aid){ var aTag = $(aid); $('html,body').animate({scrollTop: aTag.offset().top},'slow'); } scrollToAnchor(location.hash); }) </script> Link to comment
Solution mormorchu Posted October 6, 2023 Solution Share Posted October 6, 2023 (edited) On 9/19/2023 at 11:34 AM, CptFeeny said: I still need help. You shared code with me in another post but it didn't work. <!-- by @nhannhot-tuanphan --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script> <script> $(document).ready(() => { function scrollToAnchor(aid){ var aTag = $(aid); $('html,body').animate({scrollTop: aTag.offset().top},'slow'); } scrollToAnchor(location.hash); }) </script> i tried this script too but it doesn't work to me. and i tried another script from another post with similar topic: <script type="text/javascript"> function refreshPage () { var page_y = document.getElementsByTagName("body")[0].scrollTop; window.location.href = window.location.href.split('?')[0] + '?page_y=' + page_y; } window.onload = function () { setTimeout(refreshPage, 35000); if ( window.location.href.indexOf('page_y') != -1 ) { var match = window.location.href.split('?')[1].split("&")[0].split("="); document.getElementsByTagName("body")[0].scrollTop = match[1]; } } </script> it doesn't work to me too, then i try to ask ChatGPT what the script is about, it says: in a nutshell, this script refreshes the page every 35 seconds and then scrolls to the previous position. XD then i ask ChatGPT to rewrite the script for me, i paste it into footer section and finally works!!!!! here you are: <script type="text/javascript"> // Store scroll position in history state when leaving the page window.addEventListener('beforeunload', function() { history.replaceState(scrollY, null, ""); }); // On page load, if there's a scroll position in history state, restore it window.addEventListener('load', function() { if (history.state !== null) { window.scrollTo(0, history.state); } }); </script> try it!!! my website: www.mormorchu.com btw, i m also struggling on changing currency in the website so that customer can buy with their preferred currency, any people has good solution for that? Edited October 6, 2023 by mormorchu tuanphan 1 Link to comment
CptFeeny Posted October 11, 2023 Author Share Posted October 11, 2023 @mormorchu Brilliant! THANK YOU!!!!! I never would have thought to ask ChatGTP for help. I'm so happy this solution worked. ❤️ 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