Create a new element of type 'script' using document.createElement('script') and set its properties accordingly. Something I found on one of the sites. Write this at the top of the script file in which you plan on including your file.
if (typeof(km_scripts) == 'undefined') var km_scripts = new Object();
km_myclass_import('importedfile.js');
function km_myclass_import(jsFile) {
if (km_scripts[jsFile] != null) return;
var scriptElt = document.createElement('script');
scriptElt.type = 'text/javascript';
scriptElt.src = jsFile;
document.getElementsByTagName('head')[0].appendChild(scriptElt);
km_scripts[jsFile] = jsFile; // or whatever value your prefer
}
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
If you have access to PHP:
<?php
header("Content-Type: text/javascript");
include "script1.js";
include "script2.js";
?>
Save as 'allscripts.php' and link as if it were a js file:
<script type="text/javascript" src="allscripts.php"><!--screwIE6--></script>
This might not be ideal in all situations...
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
Alex, there is as such no 'simple' way of doing the thing you are trying to achieve. If yours is a client side only Javascript application, use the approach which I had mentioned in my previous post. If you are using your Javascript file in a dynamic page, use the approach provided by Matt.
Each and every server side language has its own way of doing it. If using PHP, use the method specified by Matt. If using JSP, you can use the include directive to do the same.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
You can have more than one script tag in your hrml.
MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
But I guess that is not what he is looking for.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734