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:
<script>
var url = 'http://example.com/scripts/js.php?foo=bar';
url += location.search.replace(’?',’&’);
var s = document.createElement(’script’);
s.setAttribute(’type’,'text/javascript’);
s.setAttribute(’src’, url);
// get the script’s ‘outer html’ and add it to the document.
var t = document.createElement(’div’);
t.appendChild(s);
document.write(t.innerHTML);
</script>
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?
UPDATE If I load the page by pressing Ctrl + F5, everything works fine...why is this? The script at http://example.com/scripts/js.php are a bunch of document.write calls.