title: When to use "window.onload"?
body: <p>In JavaScript, when I want to run a script once when the page has loaded, should I use <code>window.onload</code> or just write the script?</p>
  
  <p>For example, if I want to have a pop-up, should I write (directly inside the <code>&lt;script&gt;</code> tag):</p>
  
  <pre><code>alert("hello!");
  </code></pre>
  
  <p>Or:</p>
  
  <pre><code>window.onload = function() {
      alert("hello!");
  }
  </code></pre>
  
  <p>Both appear to run just after the page is loaded. What is the the difference?</p>