Jump to content

Archived

This topic is now archived and is closed to further replies.

brown2005

importing .js files

Recommended Posts

echo"<SCRIPT language='JavaScript' type='text/javascript' src='$config_url/include/scripts/functions.js'></SCRIPT>";
echo"<SCRIPT language='JavaScript' type='text/javascript' src='$config_url/include/scripts/pops.js'></SCRIPT>";

hi,

instead of using a line like above for the two scripts can i have one line say

echo"<SCRIPT language='JavaScript' type='text/javascript' src='$config_url/include/scripts/all.js'></SCRIPT>";

and in the all.js import both of the top scripts....

Share this post


Link to post
Share on other sites
Why don't you just combine the 2 scripts into 1?

Share this post


Link to post
Share on other sites
well i could, but it is easier to keep it seperated into different files for easier access for changes or using on different websites.. etc...

Share this post


Link to post
Share on other sites
What you could do is have a js.php file the 2 echos in it, then include the js.php into your main file.

Share this post


Link to post
Share on other sites
I would go with the PHP solution to write out the <script> tags, but if you want javascript only, you can make an importer file like this
[code]
var inc = new Array("file1.js","file2.js","file3.js");

var sc = "script";

for(i=0; i<inc.length; i++){
document.write("<"+sc+" language='javascript' src='"+inc[i]+"'></"+sc+">");
}
[/code]
and include that file in the header section.

Share this post


Link to post
Share on other sites
I have a php app that generates a form that "imports" a lot of js scripts, conditionally, depending on needs.  I use the file_get_contents function to load content of the js files into a php var which is then appended to the html content.  Make sure that any necessary <script> tags are in the "js" files.  Works great!

Jim

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.