title: Bulletproof "back to top" anchor that works with base href?
body: <p>How can I create a bulletproof "Back to top" anchor that works regardless of whether the site has a base href or not?</p>
  
  <p>Should I use script to sniff the current URL of the page and dynamically create the anchor?</p>
  
  <p>Anchor at the top of the page is:</p>
  
  <pre><code>&lt;a id="top"&gt;&lt;/a&gt;
  </code></pre>
  
  <p>"Back to top" link is at the bottom of the page:</p>
  
  <pre><code>&lt;a href="#top"&gt;Back to top&lt;/a&gt;
  </code></pre>
  
  <p>However, when there is a base href present on the page, regardless of the current directory, the "back to top" always resolves to the base href. How can I overcome that?</p>