I want to include a javascript library to my HTML page from inside my HTML body. i included the following script in my body part :
<script type = "text/javascript" >
var scriptHeader = document.createElement('script');
scriptHeader.setAttribute("type","text/javascript")
scriptHeader.setAttribute("src", 'http://dygraphs.com/dygraph-combined.js' );
if (typeof scriptHeader!="undefined") {
document.getElementsByTagName("head")[0].appendChild(scriptHeader);
// alert( "Success!!" );
}
else {
}
</script>
Now in I call my JS as
<script type = "text/javascript">
var plot = new Dygraph(
// ... create new graph
</script>
With out the 'alert', this is not working. It is throwing
ReferenceError: Dygraph is not defined
I assume this is a sync issue. How can I solve this?