PDA

View Full Version : nested calling of external files


Tails
02-04-2003, 08:01 PM
We all know that javascript is a tag that cannot be nested inside SCRIPT tags. But is there a way to call another file through an IF statement? To have everything all on one page or loaded at once when only one path of choices will be used seems fruitless.

Vladdy
02-04-2003, 08:06 PM
script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'somescript.js';
document.getElementsByTagName('head')[0].appendChild(script);

Tails
02-05-2003, 08:06 PM
Thanks. I will try that later. I didn't even know there was such thing as create element. Sometimes I find myself viewing all the IE files searching for readable things like tags and commands since there's no place that lists them all. It worked in startup files like command.com afterall. DOS 6.22 has the truename command and that was stripped in XP. I bet there's not a site that lists half of all the commonly used things in JS. But show me if you find one please?

Vladdy
02-05-2003, 08:39 PM
www.w3c.org - start with DOM2 Core and DOM2 HTML, see DOM2 Events next, but keep in mind that IE does not support them yet.

Tails
02-06-2003, 07:49 PM
Support them yet...
What do I do for IE 5.0? I am unable to upgrade to 6.0 without an internet connection at home because Microsoft loves those downloadable exe files that have to transfer data live from their sites. If I could save the full program, that would be too easy. What am I supposed to do? But the W3 has stuff for the old DOMs and HTML 4.0 standards still around, right?

Roy Sinclair
02-07-2003, 04:56 PM
The classic way this has been done:


<script>
if (some condition) document.write("<" + "script src=\"anotherscript\"><" + "/script>");
</script>

Tails
02-07-2003, 08:13 PM
I tried the "classic" way minus the part of separating the angle brackets. Logically, it doesn't seem to change anything, but I'll try that too.

Roy Sinclair
02-07-2003, 08:44 PM
Originally posted by Tails
I tried the "classic" way minus the part of separating the angle brackets. Logically, it doesn't seem to change anything, but I'll try that too.

Seperating the angle brackets isn't optional, if the javascript interpreter see's <script> or </script> as it's parsing a script even inside a literal it assumes you've made an error and stops.

whammy
02-08-2003, 12:05 AM
You can also comment them out like:

var authstring = "<script type=\"text/javascript\" src=\"" + location.search.substring(1) + ".js\"><\/script>";
if(location.search) document.write(authstring);

Tails
02-08-2003, 06:30 PM
Thanks. Now that you mention it, tags don't belong in script tags at all, do they? They must have gone through alot of trouble making the exception of <!-- -->. Today nobody really uses them anymore. I wouldn't think they were standard because the new standards use javascript capable browsers anwyay.