How do I add a javascript file to the body from a javascript file that is in the same directory. Java server has 2 JSF2
I have a file test.js
, it has an initialization function window.onload = function initiliaze() { ... }
that gets called whenever a window is created.
I would like to include another javascript file "d3.min.js", which is in the same directory as the file test.js
, in the HTML body when called initiliaze()
.
This is how I include my javascript file in the 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 cannot name the functions d3.min.js
, Firebug shows that d3 is not loaded.
source to share
As adeneo suggested, I removed the include script code from the init function and pasted this in the * .jspx header instead (I am using Java server faces):
<script type="text/javascript" src="#{facesContext.externalContext.requestContextPath}/resources/script/d3.min.js"/>
Thanks to Halcyon, adeneo, Explore-X, Morten helped me.
source to share