You can use the createElement:
var link = "http://example.com/script.js?ref="+location.href;
script1 = document.createElement('SCRIPT');
script1.type="text/javascript";
script1.src = src1;
document.head.appendChild(script1);
EDIT:
If you can append the script in the head or body putting
document.head.appendChild(script1);
or
document.body.appendChild(script1);
But if you can put in the specific point (id of one div or input), you can put with:
document.getElementById("NAMEOFID).appendChild(script1);