Jump to content


Photo

importing .js files


  • Please log in to reply
6 replies to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 30 June 2006 - 01:35 PM

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

#2 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 30 June 2006 - 01:42 PM

Why don't you just combine the 2 scripts into 1?

#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 30 June 2006 - 01:45 PM

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

#4 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 30 June 2006 - 01:53 PM

What you could do is have a js.php file the 2 echos in it, then include the js.php into your main file.

#5 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 03 July 2006 - 05:27 PM

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.

NoGray.com


#6 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 03 July 2006 - 09:06 PM

yeah, thats a good idea too

#7 Jim from Oakland

Jim from Oakland
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 04 July 2006 - 06:12 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users