title: How to immediately redirect using JavaScript
body: <p>How can I get javascript to <strong>immediately</strong> stop script execution and change to another page.  Consider this:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script&gt;
          function onload()
              {
                  alert('before');
                  window.location.href = 'http://google.com';
                  alert('after redirect');
              }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="onload();"&gt;
      Hello World!
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The second alert message always fires.</p>