"Brit" <mo***@english.net> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello,
I have been trying to include a js file from within another js file. I
can get this to work for firefox, but not i.e.
What I have is
a.html ...
<script language='JavaScript'
src='b.js'></script><script>Function();</script>
b.js ....
function Function() {
var s1 = "";
document.write("<sc" + s1+ "ript language='JavaScript'
src='c.js'></sc" + s1 + "ript>");
document.write("<sc" + s1+ "ript language='JavaScript'>Func2();</sc" +
s1 + "ript>");
}
and then c.js
I tried the s1="" from another googled post - no joy.
if I change a.html to
<script language='JavaScript' src='cb.js'></script>
<script language='JavaScript'
src='b.js'></script><script>Function();</script>
it works.
Is anyone able to get this to work with IE 6?
Thanks - Bryan.
Here's what I use (I have this in a 'util.js' file that I load 'manually'
(with a <script src=...> element):
====================
var Included={};
function Include() {
var src, url, heads;
heads = document.getElementsByTagName("head");
if (heads.length==0) {throw new Error(0x8009000,"Include: No <head> tag
exists. Scripts not loaded.");}
url = document.URLUnencoded;
for (a=0; a<arguments.length; a++) {
src = arguments[a];
if (Included[src]) continue;
Included[src] = true;
if (url.substr(0,5)=="file:") {
if (src.charAt(0)=="/") src = "C:<your webroot directory full path>"+src;
else src = url.slice(7,url.lastIndexOf("\\")+1)+src;
}
heads[0].appendChild(document.createElement("<script language='JavaScript'
src='"+src+"' />"));
}
}
====================
Then in the '<head>' I put:
<script
language="javascript">Include("/_ScriptLibrary/MyScript.js","LocalScripts.js",...)</script>
You may also use Include() in other 'Included' or manually loaded script
files, but may not reference their contents until the parent file is fully
loaded.
This works fine in IE6 but is untested in any other enviromant.