RES: [Javascript] Including additional javascript files

Allard Schripsema allard-schripsema at procergs.rs.gov.br
Mon Apr 4 12:27:53 CDT 2005


you can do that like this:

function Loadscript(name){
   document.write('<script src="', name, '"
type="text/JavaScript"><\/script>');
}

in your page something like:
<script>
if (red == true) {
   Loadscript("includeRed.js");
}else{
   Loadscript("includeBlue.js");
}
</script>

That should work..

allard Schripsema

-----Mensagem original-----
De: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu]Em nome de Alex Robinson
Enviada em: segunda-feira, 4 de abril de 2005 14:01
Para: [JavaScript List]
Assunto: Re: [Javascript] Including additional javascript files


>>Some time ago I stumbled across a technique for including
>>additional external javascript files that mirrored the way that
>>additional CSS files can be included via the @import statement.
...
>A <script> tag in the header can reference an external file:
>
>         <script src="external.js" type="text/javascript"></script>

Sigh. Yes, looking at my post I can see that I was not explicit
enough in my intent.

Yes, I'm fully aware that you can include javascript files the way
that you've pointed out.

What I'm talking about is including further files from within the
included file. That's why I made the reference to the @import
statement in CSS where you can do something like:

A.css
@import "B.css"

B.css
@import "C.css"

(etc, as long as the statement comes before any rule blocks, that is)


Now, obviously you can't just put a <script src="foo"> in your
javascript files, but I did, as I said, once stumble upon an example
that showed a method for achieving that very end. That's what I'm
after.
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list