Return to same scroll position in dawn theme

Anyone knows how to return to the same scroll position in dawn theme? I saw a fix for turbo theme which didn’t apply for dawn.

Hi @oudelegance

Add this script to your theme.liquid file or base.js:

window.addEventListener("beforeunload", () => {
  sessionStorage.setItem("scrollPosition", window.scrollY);
});

window.addEventListener("load", () => {
  const scrollPosition = sessionStorage.getItem("scrollPosition");
  if (scrollPosition) {
    window.scrollTo(0, scrollPosition);
  }
});

How it works:

  1. When you leave the page, the scroll position is saved in sessionStorage.
  2. When you return to the page, the scroll position is restored.

Hi @oudelegance I was facing the same issue, and the code shared by @kirillatwally worked perfectly for me. You should give it a try.
Thank you :blush: :blush: :blush: :blush: :blush: :blush: :blush: :blush: :blush:

Hi @oudelegance

I hope you are well. You can follow our instructions below:

Step 1: Shopify admin > Online store > Edit code: https://prnt.sc/M4p-gua99Uf4
Step 2: Search for “theme.liquid” file: https://prnt.sc/b6xveIKe-Rh2
Step 3: Open the file search for tag and add the following code above tag.


Here is the code for Step 3:

Please let me know if it works. Thank you!

Best,
Daisy - Avada Support Team.

Hi, thank you for your response.
I couldn’t search for it doesn’t exist like that in theme.liquid.
So I pasted it here (see screenshot). Now does it need to be indented. This did not work for me. By the way, I am having this issue on mobile phone. When you click on a product from one of the collections, then click back, it takes you to the top of the homepage, not where you clicked on the product in the first place.

Hi @oudelegance

From the screenshot you shared, could you please scroll down to the bottom to find </body tag?

Best,
Daisy - Avada Support Team.