title: How to call a function
body: <p>I've been looking for an answer to this question for 4 hours now, with no success.</p>
  
  <p>Well, what I'm trying to do execute a function that does something if the user is using a certain browser.</p>
  
  <p>I have the script used for detecting the browser, version, and OS in the head section of the page, and it works.</p>
  
  <p>If I use the code below in the body of my page it works fine.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  if (BrowserDetect.browser == "Chrome")
  {
     document.write("You're using Chrome")
  }
  else
  {
      document.write("You're not using Chrome")
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>But if I put the code in an external script sheet, how do I use it?
  I tried putting it in a function and calling that function on load by using this code.</p>
  
  <pre><code>&lt;body onload="BrowserDetect();"&gt;
  </code></pre>
  
  <p>Note that the external script sheet is called in the head section of my page.</p>
  
  <p>And this is the code in the external script sheet.</p>
  
  <pre><code>function BrowserDetect()
  {
      if (BrowserDetect.browser == "Chrome")
      {
          document.write("You're using Chrome")
      }
      else
      {
          document.write("You're not using Chrome")
      }
  }
  </code></pre>
  
  <p>As you can see, it's the exact same code that worked when it was in the body of the web page. But when it's put in a function and called on load, it doesn't work. Why?</p>