Tom Cole said the following on 9/26/2006 8:12 AM:
Randy Webb wrote:
>Tom Cole said the following on 9/25/2006 4:11 PM:
>>Jon Paal wrote:
this works as shown:
<script Language="javascript" src="http://127.0.0.1/syndicate.ashx?d=suppliers"></script>
is there a way to set src programmatically ??
It uses my own library as an example, but this did work for me:
Did you test it in anything besides IE? You should test it there as the
only UA that allows the changing of the .src property of a script
element is IE.
No I didn't (obviously). I need to remember to do that when making
quick test cases for people like this....
>Although dynamically creating script elements is very widely supported,
you simply createElement('script') and then set it's .text property to
the script block.
Thanks for the heads up. What if you wanted to include a prepackaged
..js file rather than an actual block of script?
Then you set the new script element's .src property instead of its .text
property:
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')
If you want to execute script code then use something like this:
function executeJSCode(stringToExecute){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.text = stringToExecute;
document.getElementsByTagName('head')[0].appendChild(newScript);
}
And call it as such:
executeJSCode('String of code here without script tags')
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/