Posted By

MMDeveloper on 09/16/08


Tagged

javascript file external loading


Versions (?)

programatically loading external js/css files


 / Published in: JavaScript
 

  1. function loadExternalFiles(array) {
  2. outString = "";
  3.  
  4. for (x in array) {
  5. switch (array[x][1]) {
  6. case "js":
  7. outString += '<script type="text/javascript" src="' + array[x][0] + '"></script>';
  8. break;
  9.  
  10. case "css":
  11. outString += '<link rel="stylesheet" type="text/css" href="' + array[x][0] + '" />';
  12. break;
  13. }
  14. }
  15.  
  16. return outString;
  17. }
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. var serverName = "http://nric-20896/zWebHost/";
  28.  
  29. document.write(loadExternalFiles(new Array (
  30. // [serverName + "js/fordmJS_misc.js", "js"], //combined with this file
  31. [serverName + "skins/skin_0/css/mfstyle0.css", "css"],
  32. [serverName + "skins/skin_0/css/layNav.css", "css"],
  33. [serverName + "skins/skin_0/css/cal.css", "css"],
  34. ["http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js", "js"],
  35. ["http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/scriptaculous.js", "js"],
  36. [serverName + "js/livepipe.js", "js"],
  37. [serverName + "js/window.js", "js"],
  38. [serverName + "js/calendar.js", "js"],
  39. [serverName + "js/layNav.js", "js"]
  40. )
  41. ));

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: MMDeveloper on September 16, 2008

that last bit should actually be

document.write(loadExternalFiles(new Array ( // [serverName + "js/fordmJSmisc.js", "js"], //combined with this file [serverName + "skins/skin0/css/mfstyle0.css", "css"], [serverName + "skins/skin0/css/layNav.css", "css"], [serverName + "skins/skin0/css/cal.css", "css"], ["http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js", "js"], ["http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/scriptaculous.js", "js"], [serverName + "js/livepipe.js", "js"], [serverName + "js/window.js", "js"], [serverName + "js/calendar.js", "js"], [serverName + "js/layNav.js", "js"] ) ));

it was missing a comma

You need to login to post a comment.