Adding external JavaScript file into DOM via JavaScript
<p>I need to load an external JavaScript file that is generated by a PHP script, I also want to pass any query string parameters to the script as well, I came up with the following solution: </p>

<pre>
<code>
&lt;script&gt;<br/>var url = 'http://example.com/scripts/js.php?foo=bar';<br/>url += location.search.replace(&#x2019;?',&#x2019;&amp;&#x2019;);<br/><br/>var s = document.createElement(&#x2019;script&#x2019;);<br/>s.setAttribute(&#x2019;type&#x2019;,'text/javascript&#x2019;);<br/>s.setAttribute(&#x2019;src&#x2019;, url);<br/><br/>// get the script&#x2019;s &#x2018;outer html&#x2019; and add it to the document.<br/>var t = document.createElement(&#x2019;div&#x2019;);<br/>t.appendChild(s);<br/>document.write(t.innerHTML);<br/><br/>&lt;/script&gt;
</code>
</pre>

<p>This works in all browsers except IE (go figure), I believe the problem is that the generated script also downloads more JS, which seems to hang... Is there a better way to do something like this?</p>

<p><strong>UPDATE</strong>
If I load the page by pressing Ctrl + F5, everything works fine...why is this? The script at <a href="http://example.com/scripts/js.php" rel="nofollow">http://example.com/scripts/js.php</a> are a bunch of document.write calls.</p>
