3

I have test.js file, it has an initialization function window.onload = function initiliaze() { ... }, which is invoked whenever the window is created.

I would like to include other javascript file "d3.min.js" , which is located in the same directory as test.js file is located, into the HTML body when initiliaze() is called.

This is how I include my javascript file into HTML body, from the same directory:

var js = document.createElement("script");

js.type = "text/javascript";
js.src = "./d3.min.js";

document.body.appendChild(js);

however I still can't call d3.min.js functions, Firebug shows that d3 is not loaded.

kolossus
  • 20,559
  • 3
  • 52
  • 104
Benas
  • 2,106
  • 2
  • 39
  • 66

1 Answers1

0

As adeneo suggested I removed my script inclusion code from initialization function and instead pasted this in *.jspx header (I'm using Java server faces) page:

<script type="text/javascript" src="#{facesContext.externalContext.requestContextPath}/resources/script/d3.min.js"/>

Thanks to Halcyon, adeneo, Explore-X, Morten for helping me out.

Benas
  • 2,106
  • 2
  • 39
  • 66