0

Possible Duplicate:
How do you dynamically load a javascript file? (Think C's #include)
Include JavaScript file inside JavaScript file?

I know that one can link to external javascript files with html code akin to:

<script type="text/javascript" src="http://external.com/code.js"></script>

Is there a way to do this within a javascript (.js) file?

Community
  • 1
  • 1
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206
  • may be it will help you http://stackoverflow.com/questions/21294/how-do-you-dynamically-load-a-javascript-file-think-cs-include – Vilva Jan 22 '12 at 04:24
  • Thanks, but I think neither method is working for my example using the Google Visualization API: http://jsfiddle.net/V9jdu/ – dangerChihuahua007 Jan 22 '12 at 04:45

2 Answers2

3

Create a script element and append it to the DOM. That should load your other script.

var newScript = document.createElement("script");
newScript.setAttribute("type","text/javascript");
newScript.setAttribute("src","http://external.com/code.js");
body.appendChild(newScript);
mgibsonbr
  • 21,755
  • 7
  • 70
  • 112
1

You could try the answer given in this question.

Community
  • 1
  • 1
Matt Healy
  • 18,033
  • 4
  • 56
  • 56