Jump to content

ScottoCat

Member
  • Posts

    21
  • Joined

  • Last visited

Posts posted by ScottoCat

  1. Hello, Once again script has stopped working on my site. It is one of the most important features. I guess every time they do an update? Because there is a lot of scrolling with many individual posts I need the user to return to where they were on the posts page when they click the back arrow. I found script that works BUT only after the 2nd click back.  I need it to happen every time. Is there a way to alter this or does anyone have script that would work.? 

    Thanks!

    Here It is:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <script type="text/javascript">
    if (window.performance && window.performance.navigation.type === window.performance.navigation.TYPE_BACK_FORWARD) {
       if (localStorage.getItem("my_app_name_here-quote-scroll") != null) {
            $(window).scrollTop(localStorage.getItem("my_app_name_here-quote-scroll"));
        }
    } else {
       $(window).scrollTop();
    }
    window.addEventListener('beforeunload', function (e) {
            if (window.performance && window.performance.navigation.type === window.performance.navigation.TYPE_BACK_FORWARD) {
            localStorage.setItem("my_app_name_here-quote-scroll", $(window).scrollTop());
            } 
     });
    </script>

     

  2. Hello, If you go to my site head over to Newer Albums. The pagination arrows are only at the bottom. I would like to have them at the top as well. Does anyone know code that I could add to the post pages settings header. I would like it to be just under the search bar. The second picture shows the current pagination, which I would like to keep.

    Arrows.jpg

    Screenshot 2023-07-01 at 9.51.39 AM.png

  3. I am having a similar issue except it goes to the top of the page. The JS i had in the code injector stopped working after working for 4 + years. Does anyone now how to fix this. Here is the current code that isn't working:

    <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, 3600000);
          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>

  4. I had to upgrade my plan to be able to unlock the code injector. Now I just need code that will do what it did before. Here is the code now that I can copy/paste:

    <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, 3600000);
          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>

  5. Hello, I have had code that has worked for years where when you hit the back arrow you return to where you were on the scroll. It's important with my site, especially on mobile. The back arrow is returning you to the top of the page rather than where you left off. I remember i got code to insert. I am also not sure why it suddenly stopped working.

  6. On 6/18/2020 at 11:08 AM, colin.simmons said:

    Hey friends, 

    Here's a snippet of code that I use to save the scroll position. I use it when a user has navigated away from a long index page and I want them to return to the same place.

    Note, for an index, you must add it in the code injection for the INDEX, not the page section. 

    
    <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>

    Let me know if this helps!

    This one worked great. I land at the top of each post and don't loose the spot on scrolls. This was especially important on smartphones. One question; can Ajax be enabled with this script. I am afraid to try it.

  7. My site has a lot of scrolling. The template Avenue returned you to where you were on the page. I switched to Brine template to have more control on the post. But I found out this annoying thing where back arrows bring you to the top of the page. I can imaging this will get old to the users experience. I am about to inject the code above but am uncertain as to which section. Also i am nervous that I will break my site. If something bad happens can I simply go in and remove it?

  8. On 12/25/2020 at 8:01 PM, Helen_Phan said:

    Try this code. It works for me.

    
    <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>

     

    Helen, Where do I drop this code in Header, Footer or Order Conformation sections

×
×
  • 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.