By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,400 Members | 1,322 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,400 IT Pros & Developers. It's quick & easy.

changing scripts on the fly - works in IE but not in FF

P: n/a
<script>
document.getElementsByTagName(/script/.source)[0].src='http://www.domain.tld/script.js';
</script>

If script.js does simply "alert('hello, world!')" then only IE will
actually display the "hello, world!" message. FireFox will do nothing.
Since, in this case, I prefer IE's behavior, does anyone have any
ideas as to what I could do to get this working in FireFox?

Jul 8 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
yawnmoth said the following on 7/8/2006 1:23 AM:
<script>
document.getElementsByTagName(/script/.source)[0].src='http://www.domain.tld/script.js';
</script>

If script.js does simply "alert('hello, world!')" then only IE will
actually display the "hello, world!" message.
Thats because IE is the only one that allows you to change the .src
property that way.
FireFox will do nothing.
Probably puts an error message in the Error Console.

Since, in this case, I prefer IE's behavior, does anyone have any
ideas as to what I could do to get this working in FireFox?
Why not a way that works in any dynamic browser?

function loadJSFile(fileURL){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.src = fileURL;
document.getElementsByTagName('head')[0].appendChild(newScript);
}

and then call it like this:

loadJSFile('URLToJSFile');

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 8 '06 #2

P: n/a
"yawnmoth" <te*******@yahoo.comwrites:
document.getElementsByTagName(/script/.source)[0].src='http://www.domain.tld/script.js';
Just as a comment (since Randy Webb already answered your question),
using /script/.source is just a convoluted way of writing the string
"script".

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.