Stop auto scroll to top on mobile device | Dawn

Hello guys,

I have a problem with auto scroll top on mobile. When I back from product/page I am immediately sent to the top. Very unpleasant experience. In previous discussions I found the following code:

{{ content_for_layout }}

It said to delete lines 1 and 3 and it would work. The real ones were working, but today I noticed that everything is back.

https://d5ab0f.myshopify.com/

Password: amber

Thank you so much!

Hello @Atsimataves , to do that, you can find the theme.liquid file and add the following code:

<script>
if (window.location.pathname === '/') {
    if (localStorage.getItem("my_app_name_here-quote-scroll") != null) {
        const savedScrollPosition = localStorage.getItem("my_app_name_here-quote-scroll");
        window.scrollTo(0, savedScrollPosition);
    }
    window.onscroll = function() {
        localStorage.setItem("my_app_name_here-quote-scroll", window.scrollY);
    };
}
</script>

This code will save the location of the page before being routed to another page into localStorage. Then when you return to the page, the website will take the location saved in localStorage and move to that location. Hope this can help you.

1 Like

@BSS-Commerce Mystical, but for now my method written before works. Anyway, I saved this code in a draft and will definitely use it!

Thank you very much for your time and help. :yellow_heart:

Hi, I tried this and it didn’t work unfortunately, can you help me please I am having the same problem? When browsing products on my website through a link on Instagram and you click the back button it takes you back to the top of the page.