title: How do I reload the page AND jump to an anchor?
body: <p>I am trying to refresh a page when it gets a message from a service worker, which happens when there is new content to be seen (which is what the anchor should be jumping to when the page is refreshed).</p>
  
  <p>So imagine I have these:</p>
  
  <pre><code>var url = 'http://example.com/home.htm';
  var anchor = '#comment-45';
  </code></pre>
  
  <p>and the page with that url is already loaded. I want to reload the page, and jump to #comment-45.</p>
  
  <p><strong>All of these don't work:</strong></p>
  
  <p>This doesn't reload the page, just tries to jump to the nonexistant anchor:</p>
  
  <pre><code> window.location = url+anchor;
  </code></pre>
  
  <p>Changes to correct URL and reloads, but doesn't jump to new anchor:</p>
  
  <pre><code>    window.location.hash = anchor;
      window.location.reload(true);
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>    window.location.href = url+anchor;
      window.location.reload(true);
  </code></pre>
  
  <p>Reloads the page to the base URL, but doesn't change the anchor:</p>
  
  <pre><code>    window.location = url;
      window.location.hash = anchor;
  </code></pre>