Without using any framework (with thanks to CodeJoust):
// a is the script to call
// b is the ID of the script tag (optional)
function scriptc(a,b){
var __d=document;
var __h = __d.getElementsByTagName("head")[0];
var s = __d.createElement("script");
s.setAttribute("src", a);
s.id = b;
__h.appendChild(s);
}
scriptc("http://example.com/someother.js");
// adds to DOM and it'll get loaded
However take caution because the script on other domains can access sensitive information on your domain, such as the Session ID through cookies in PHP.
Example:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="cool">testing</div>
<script type="text/javascript">//<!--
function scriptc(a,b){
var __d=document;
var __h = __d.getElementsByTagName("head").item(0);
var s = __d.createElement("script");
s.setAttribute("src", a);
s.id = b;
__h.appendChild(s);
}
scriptc("http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js");
// --></script>
</body>
</html>
After which is loaded, I use Firebug to examine $("#cool").html().