I got a portion of javascript code embedded in HTML (generated on the server side) that looks like this:
function winWriteMail2(){
var win = open(\'\',\'wi
Think your DOM-based code is fine, but try to (a) use the absolute script URL, (b) set the script type and (c) update src after appending, this should make it working more reliably:
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.type = "text/javascript";
head.appendChild(script);
script.src = "http://host.tld/js/JSFILE.js";
Hope this helps.
EDIT
By the way, it is good idea to set up kind of callback, to make sure script was loaded before using its code. Code can look similarly to this:
// most browsers
script.onload = callback;
// IE
script.onreadystatechange = function() {
if(this.readyState == "loaded" || this.readyState == "complete") {
callback();
}
}
Here callback is literally the function to execute.