• Resolved kowabungawp

    (@kowabungawp)


    Hi,

    Is there a way to keep the anchor link (e.g. url.com/#section-2) in the URL to scroll to a specific section with that ID? It works fine without age gate, but when I try in a private window it scrolls to the top after form submit.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Phil

    (@philsbury)

    If you know what the hash needs to be, you can do:

    window.addEventListener('age_gate_passed', event => window.location.hash = 'section-2');

    If you don’t know what it is, there may still be a way to do it, so let me know

    Thread Starter kowabungawp

    (@kowabungawp)

    Thanks!! I was able to make it work with that event. I got the hash directly from the URL since there are multiple anchors as options. I also added a delay because it was redirecting to the top at first.

    window.addEventListener('age_gate_passed', function() {
      // Get the hash from the current URL
      var hash = window.location.hash;
    
      // Check if the hash is not empty
      if (hash) {
        // Decode the hash to handle special characters
        var decodedHash = decodeURIComponent(hash);
    
        // Remove the '#' character from the decoded hash
        var targetId = decodedHash.substring(1);
    
        // Delay the scroll
        setTimeout(function() {
          // Scroll to the section with the target ID
          var targetSection = document.getElementById(targetId);
          if (targetSection) {
            targetSection.scrollIntoView({ behavior: 'smooth' });
          }
        }, 1500); // Scroll after 1.5 seconds
      }
    });

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Keep anchor link scroll after Age Gate pop up’ is closed to new replies.