•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,670 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,277 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 5562 | Replies: 6
![]() |
•
•
Join Date: Sep 2006
Posts: 26
Reputation:
Rep Power: 2
Solved Threads: 0
I know that I can import an css file in other css file with @import
Ex: @import "style.css"; and i use this in allcss.css
Can I do something like this in javascript, import a javascript in other javascript ;
Ex: @import "style.css"; and i use this in allcss.css
Can I do something like this in javascript, import a javascript in other javascript ;
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.
javascript Syntax (Toggle Plain Text)
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 }
Last edited by ~s.o.s~ : May 20th, 2007 at 9:38 pm.
"I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
•
•
Join Date: Sep 2006
Posts: 26
Reputation:
Rep Power: 2
Solved Threads: 0
I am looking for something more simple,like in css.
The css example:
Begin with four stylesheets: simple1.css ,simple2.css,simple3.css,simple4.css reffering to navigation,headers,
special styles...
I want to load them at once,so I make another css file all.css
all.css - code
@import "simple1.css";
@import "simple2.css";
@import "simple3.css";
@import "simple4.css";
the xhtml page code
<link rel="stylesheet" type="text/css" href="all.css" />
so,I import all files in only one http request
I am looking for something similar in java script
Thanks for your above post
The css example:
Begin with four stylesheets: simple1.css ,simple2.css,simple3.css,simple4.css reffering to navigation,headers,
special styles...
I want to load them at once,so I make another css file all.css
all.css - code
@import "simple1.css";
@import "simple2.css";
@import "simple3.css";
@import "simple4.css";
the xhtml page code
<link rel="stylesheet" type="text/css" href="all.css" />
so,I import all files in only one http request
I am looking for something similar in java script
Thanks for your above post
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 943
Reputation:
Rep Power: 5
Solved Threads: 47
If you have access to PHP:
Save as 'allscripts.php' and link as if it were a js file:
This might not be ideal in all situations...
PHP Syntax (Toggle Plain Text)
<?php header("Content-Type: text/javascript"); include "script1.js"; include "script2.js"; ?>
HTML Syntax (Toggle Plain Text)
<script type="text/javascript" src="allscripts.php"><!--screwIE6--></script>
Last edited by MattEvans : May 21st, 2007 at 8:37 am. Reason: forgot to screw IE6..
If it only works in Internet Explorer; it doesn't work.
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.
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.
"I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
But I guess that is not what he is looking for.
"I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- disable javascript through javascript in firefox (JavaScript / DHTML / AJAX)
- Creative element selection with JavaScript (JavaScript / DHTML / AJAX)
- Having trouble running javascript (JavaScript / DHTML / AJAX)
- I just can't get this Javascript (JavaScript / DHTML / AJAX)
- Request Header Parsing in Javascript (JavaScript / DHTML / AJAX)
- Using Javascript code in ASP.NET (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Round Numbers
- Next Thread: Email validation using java script



Linear Mode