I came across this technique when I was trying to get around the cross-domain restrictions applied by modern browsers to the XMLHttpRequest object. Basically you can't do it.
This got me thinking, how does Google Maps do it? I have Google Map code in pages hosted on my domain. Somehow it's going to the Google server, from the browser, to get images. It can't be using XMLHttpRequest to do it, so how does it work?
My example here doesn't actually get the scripts off an external server or dynamically generate the script. The example has buttons that insert a script element into the head element when clicked. The script elements source attribute depends on which button is clicked, but both local script files display an alert message when loaded.
To see this example running, just open the folder as a Website in Visual Studios and run it. I'll add a link to a live demo soon.