Forum Moderators: phranque

Message Too Old, No Replies

include a JavaScript file inside a JavaScript file

         

mossimo

9:10 pm on Sep 9, 2003 (gmt 0)

10+ Year Member



Is there a way to include a JavaScript file inside a JavaScript file without additional <script></script> tags?
The idea is to break up a large JavaScript file into several includes all inside of one open and close tag.

For example:

<script language="JavaScript1.2">
function myfunc() {
if (document.bla) {
document.bla[name].document.close();
}

includefile.js here
function myfunc() {
document.bla[name].document.write(message);
} else {
if (document.bla) {
eval("document.bla." + name + ".innerHTML='" + message + "'");
}
}
</script>

claus

9:20 pm on Sep 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to write the include string to the document using javascript and you need to include the <script> tags as well, otherwise it won't be interpreted as such.

I posted it yesterday, post #6 here, hope it works in your case as well, although i am not sure it will work from inside an include (i guess it depends on how the script is called and such): [webmasterworld.com...]

/claus

mossimo

9:50 pm on Sep 9, 2003 (gmt 0)

10+ Year Member



Missed that post maybe I should read more and type less.

HAY! worked great thanks claus,
except i get errors from the include file (because it's out of context) I don't think JS was meant to do this so what can I say.

This will kill the errors but it's a little hacky
function stoperror(){
return true}
window.onerror=stoperror