Jump to content

Need Help Returning to Same Place on Previous Page (Mobile)

Go to solution Solved by mormorchu,

Recommended Posts

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

 

 
 

 

 
 

Edited by CptFeeny
Added website URL
Link to comment
  • 2 weeks later...
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
  • 3 weeks later...
  • Solution
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 by mormorchu
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.