View Full Version : include javascript
jeorg
11-20-2002, 07:50 AM
is there a possibility in stead of writting in the head
<script scr="sc1.js"></script>
<script scr="sc2.js"></script>
<script scr="sc3.js"></script>
<script scr="sc3.js"></script>
only on time
<script scr="sc.js"></script>
and write in it the address of other scripts, like an include file in asp
?
beetle
11-20-2002, 07:55 AM
sc.js
document.write('<script src="sc1.js"></script>');
document.write('<script src="sc2.js"></script>');
document.write('<script src="sc3.js"></script>');
document.write('<script src="sc3.js"></script>');
jeorg
11-22-2002, 07:55 AM
and is it something generally used ?
or is ot better not to ?
:-))) thank you
chrismiceli
11-22-2002, 01:39 PM
you could get complicate with loops and stuff like this
for (i=o; i >= 3; ++i) {
document.write('<script src="sc" + i + ".js"></script>');
}
jeorg
11-22-2002, 02:12 PM
the 1.2.3 was just to write something
thank you
beetle
11-22-2002, 03:04 PM
Some people don't like the concept of writing HTML to the page like that, especially in the HEAD, however, I have never seen it not work.
Vladdy
11-22-2002, 03:26 PM
Originally posted by beetle
<snip />
I have never seen it not work.
actually document.write would not work if you script is loaded dynamically:
scripts=document.createElement('script');
scripts.type='text/JavaScript';
scripts.src='yourScript.js';
document.getElementsByTagName('head')[0].appendChild(scripts);
This would also be a possibly better alternative for loading scripts from another script file.
....
By the way, beetle. Can you do me a favor and remove similar looking piece of code from my DOM viewer script, that you were so liberally using - my code tracker is flooded with hits:
file://C:\work\lanwizards\website\navtest\test.htm (IP = #removed per beetle's request) used DOM Tree Viewer 114 times.
file:///C:/work/lanwizards/website/navtest/blah.htm (IP = #removed per beetle's request) used DOM Tree Viewer 5 times.
file:///C:/work/lanwizards/website/navtest/test.htm (IP = #removed per beetle's request) used DOM Tree Viewer 10 times.
http://www.lanwizards.com/navtest/test.htm (IP = web) used DOM Tree Viewer 428 times.
file://D:\Inetpub\wwwroot\miscJavascriptWork\beetle.htm (IP = #removed per beetle's request) used DOM Tree Viewer 1 times.
file:///V:/Clients/Beetle/test.htm (IP = #removed per beetle's request) used DOM Tree Viewer 7 times.
http://www.lanwizards.com/navtest/test3.htm (IP = web) used DOM Tree Viewer 15 times.
http://www.lanwizards.com/navtest/test4.htm (IP = web) used DOM Tree Viewer 23 times.
http://www.lanwizards.com/navtest/test2.htm (IP = web) used DOM Tree Viewer 22 times.
file://E:\Documents and Settings\Administrator\Desktop\navtest\test.htm (IP = #removed per beetle's request) used DOM Tree Viewer 9 times.
file:///E:/Documents and Settings/Administrator/Desktop/navtest/test.htm (IP = #removed per beetle's request) used DOM Tree Viewer 2 times.
http://www.lanwizards.com/navtest/test5.htm (IP = web) used DOM Tree Viewer 2 times.
Or I start charging you on per hit basis :D :D :D :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.