I'm loading a JavaScript file on the fly. The response from the request to load this file has JavaScript in it, which I would expect to execute, but it doesn't.
This does not work (the remote script's JS does not execute):
var body = document.getElementsByTagName("body")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'https://pixel.adbuyer.com/conversion';
body.appendChild(newScript);
Whereas, this does work (the script's JS does execute):
var SWJsHost = (("https:" == document.location.protocol) ? "https://" : "http://");
document.write(unescape("%3Cscript src='" + SWJsHost + "pixel.adbuyer.com/conversion' type='text/javascript'%3E%3C/script%3E"));
What am I missing here? Why doesn't this work in the first case?