View Full Version : include javascript inside javascript
scorgit
05-05-2003, 01:33 PM
Hi all,
little (I think a dumb) problem...
I have a javascript file for a menu. Inside it, I want to take up some code to include another javascript file, depending on the accesslevel a logged in user has.
So, an admin will see the whole menu, a simple mortal will see less.
What is the code to include a javascript file into another javascript file?
Thanx!
Tom
requestcode
05-05-2003, 01:49 PM
You can't include a JavaScript file within another. The code will have to be included separately.
scorgit
05-05-2003, 02:51 PM
ok, that's all I wanted to know, so now I can move on with my live. Thnx!
kansel
05-05-2003, 09:31 PM
You can try this.
<script>
if(accesscode == "admin")
document.write("<script src=\"menu_admin.js\"><\/script>");
else
document.write("<script src=\"menu_plain.js\"><\/script>");
</script>
The <\/script> has the \ character so some browsers won't think it's the closing tag for the container script tag.
Of course you'll want to set language and type for all those script tags.
russ801
05-06-2003, 06:52 PM
Can you include multiple external scripts files?
So that admin would not only have a admin js file but also the base user file.
Vladdy
05-06-2003, 07:04 PM
if(somecondition)
{ myscript = document.createElement('script');
myscript.type = 'text/javasript';
myscript.src = 'myscript.js';
document.getElementsByTagName('head')[0].appendChild(myscript);
}
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.