javascript - Append <Script> Tag to Body? -


i want append script tag body of html page. added following in page:

<script type="text/javascript">        function loadscript() {         var script = document.createelement('script');         script.type = 'text/javascript';         script.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&' +                 'callback=initialize';         document.body.appendchild(script);     }      window.onload = loadscript;  </script> 

i tried run in jsfidle , there no problems.

when run on html page runs on demo server following error in console:

uncaught typeerror: undefined not function 

enter image description here

what causes error , how can prevent it?

edit: removing type text/javascript not change anything.

the error getting because there no initialize() function. if declare 1 there no error.

function loadscript() {     var script = document.createelement('script');     script.type = 'text/javascript';     script.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize';     document.body.appendchild(script);     console.log('loadscript'); }  function initialize() {     console.log('initialize'); }  window.onload = loadscript; 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -