title: Why doesn't window.scrollTo() work on page load?
body: <p>I have some tabbed content on a page, with hash segments in the URL that take you to the correct tab content. Nothing unusual. However, as the tabs are a short way down the page, when someone visits with a hash target in the URL, they get dropped to down the page to the tabs bit - which cuts off the top navigation bar and breadcrumbs.</p>
  
  <p>I don't want that to happen. It's disorientating.</p>
  
  <p>I thought it would be simple to rectify: something like:</p>
  
  <pre><code>$(function(){
  window.scrollTo(0,0)
  });
  </code></pre>
  
  <p>That doesn't work. You still get dropped at the hash anchor.</p>
  
  <p>I've tried calling it on window.load(). I've tried moving the script from the &lt; head > to just before the . I've tried window.scrollTo and window.scroll. Nothing works. The only script that I've been able to get to actually move me back up to the top of the page is this:</p>
  
  <pre><code>$(function(){
      setTimeout(function(){
          window.scrollTo(0,0)
      },2000);
  });
  </code></pre>
  
  <p>... which is even worse than not scrolling at all.</p>
  
  <p>Why won't anything else work? Am I doing something wrong, or is something else preventing me moving the user back to the top of the page?</p>
  
  <p>=====================
  Edit:</p>
  
  <p>An example (you may want to pad it out with some more Lorem paras). Save it to a new HTML file and then go to the #hash1 URL:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  
  &lt;head&gt;
  &lt;meta http-equiv="Content-type" content="text/html;charset=utf-8" /&gt;
  &lt;title&gt;Load&lt;/title&gt;
  
  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  /*
  
  
  // doesn't work
  $(function(){
      window.scrollTo(0,0);
  });
  
  
  // doesn't work
  $(window).on('load', function(){
      window.scrollTo(0,0);
  });
  
  
  // doesn't work
  window.scrollTo(0,0);
  
  
  // works, but horrible UX.
  $(function(){
      setTimeout(function(){
          window.scrollTo(0,0)
      },2000);
  });
  
  
  
  */
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
      quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
      consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;
  
      &lt;p&gt;&lt;a name="hash1"&gt;&lt;/a&gt;Hash 1&lt;/p&gt;
  
  
  &lt;script type="text/javascript"&gt;
      // doesn't work
      // window.scrollTo(0,0);
  &lt;/script&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>