Jump to content

colin.simmons

Circle Member
  • Posts

    21
  • Joined

  • Last visited

Posts posted by colin.simmons

  1. 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!

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