Jump to content

importing .js files


brown2005

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....
Link to comment
https://forums.phpfreaks.com/topic/13295-importing-js-files/
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.
Link to comment
https://forums.phpfreaks.com/topic/13295-importing-js-files/#findComment-52539
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
Link to comment
https://forums.phpfreaks.com/topic/13295-importing-js-files/#findComment-52976
Share on other sites

Archived

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

×
×
  • 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.