title: How do I add an external js file with a parameter
body: <p>I want to give a minimal js code to random websites so that they can add a widget.</p>
  
  <p>The code needs to run after the main page loads and include a parameter with the domain name. ( I don't want to hardcode it)</p>
  
  <p>One option is to add this code just before the <code>&lt;/body&gt;</code> (so It will run after the page loads):</p>
  
  <pre><code>&lt;script type="text/javascript" id="widget_script"&gt;  
      document.getElementById('widget_script').src=location.protocol.toLowerCase()+"//mywebsite.com/?u="+encodeURIComponent(window.location.host);        
  &lt;/script&gt;
  </code></pre>
  
  <p>This works in IE but not in Firefox. I see with Firebug that the src property is created correctly but the script from my site is not loaded.</p>
  
  <p>My question is : what is the best way to do that ? (preferably by putting minimal lines on the header part.)</p>
  
  <p>To further clarify the question: If I put a script on the header part, how do I make it run after it is loaded and the main page is loaded? If I use onload event in my script I may miss it because it may load after the onload event was fired.</p>