20050407 prerelease posting ok said the following on 7/23/2006 9:01 PM:
Hi!
Is it possible in a fairly portable manner to load additional javascript code
from a WWW URL? This would be useful for large-scale projects.
Yes, and although Rob gave you a URL to a thread that talks about how, I
am not sure it is the best, most comprehensive, thread to read about
dynamically creating JS files on the fly. Although it does give enough
to get started.
function loadJSFile(fileURL){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.src = fileURL;
document.getElementsByTagName('head')[0].appendChild(newScript);
}
And call it as such:
loadJSFile('http://www.someDomain.com/someJSFile.js')
Beware that you may run into cross-domain security issues if you are
loading JS files from domains other than your own.
Also, if you are going to do a lot of loading, it may be worth the
benefit to appendChild to a div element and then clear it out so that
the script blocks don't keep piling up on you.
--
Randy
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/