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

Y

yawnmoth

<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?
 
R

Randy Webb

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');
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top