title: Remove anchor link after scrolling - works also on links from another page
body: <p>I've set up a single page website with smooth scrolling that strips the anchor link from the URL after smooth scrolling. Here's the jQuery I'm using :</p>
  
  <pre><code>$(function() {
      $('a.page-scroll').on('click', function(event) {
          var $anchor = $(this);
          $('html, body').stop().animate({
              scrollTop: $($anchor.attr('href')).offset().top  - 60
          }, 1000, 'easeInOutExpo');
          event.preventDefault();
      });
  });
  </code></pre>
  
  <p>Everything works great until I added other pages. I can't get the anchor link to strip out after a link like <code>&lt;a class="page-scroll" href="../#contact"&gt;Contact&lt;/a&gt;</code> on another external page.</p>
  
  <p>I've searched high and low on SO but can't find a solution that works. </p>
  
  <p>I don't totally care about the smooth scrolling if the link is from an external page. What I need most is to navigate / scroll to the id section of the main page (with offset to accommodate fixed navigation) and remove the anchor link from the browser URL window when the link is from an external page (from other pages on my website, or from other websites).</p>
  
  <p>I've tried this also, but it likewise only works on internal links on to an id on the same page :</p>
  
  <pre><code>&lt;script&gt;
  $(function() {
    $('a[href*=#]:not([href=#])').click(function() {
      if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') &amp;&amp; location.hostname == this.hostname) {
  
        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
        if (target.length) {
          $('html,body').animate({
            scrollTop: target.offset().top - 60
          }, 1000);
          return false;
        }
      }
    });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>I've also tried this with no luck :</p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
  (function($) {
      $(document).ready(function() {
      var url=document.URL.split("#");
      var ancher=url[1];
           $('html, body').animate({
             'scrollTop':   $('#'+ancher).offset().top - 60
           }, 5000);
      });
  })(jQuery);
    &lt;/script&gt;
  </code></pre>
  
  <p>Any New Year's Eve help would be most appreciated so I can get this project wrapped up! </p>