Click to See Complete Forum and Search --> : loading a .js INSIDE a .js


David Harrison
04-23-2003, 12:24 PM
I have a .js file, and it's loaded on every page of my site, however on 1 of my pages I want to load one of two other .js files depending on something or other earlier on, and then I have a bit more script that I want on the end after the one of two .js files.
What I did was had a start.js file loaded, and then on the page itself I chose one of the two other .js files and then I loaded end.js .
How can I load a .js file inside a .js file so that on the page I only need to tell it to load 1 script?

If you want me to try and make myself a bit clearer ask me, because I don't know if what I have written makes sense to anyone else but me.

AdamBrill
04-23-2003, 12:37 PM
Well, if I understand right, you should be able to do something like this:

var oScript=document.createElement("script");
oScript.src="second.js";
document.getElementsByTagName('head')[0].appendChild(oScript);

You should be able to put that inside of your first .js to load the second one(second.js). ;)

David Harrison
04-23-2003, 03:51 PM
Is it essential to put oscript or is that just something that you do?

AdamBrill
04-23-2003, 03:55 PM
It doesn't matter; it's just a variable name, so change it to whatever you want. But make sure you change it in all three places...

David Harrison
04-24-2003, 02:24 PM
Are you sure that you typed in your code correctly because I tried it and it didn't work.

AdamBrill
04-24-2003, 03:00 PM
Hmm... It worked for me. What browser version are you using? I tried it in IE6 and NS7, and they both worked... I'll attach a .zip of my code for you to try... I hope that works for you. ;)