Jump to content

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>";


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....
Link to comment
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
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+">");
and include that file in the header section.
Link to comment
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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

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.