How to load a Javascript file without Script tag? -


i have code have nested <script> tag, inner script tag nothing loads javascript file using src attribute. because, how in code, inner script tag closing outer script.

since inside javascript mode, there way load script without using <script src=""> call?

var js = document.createelement("script");  js.type = "text/javascript"; js.src = "path_to_the_file.js";  document.body.appendchild(js); 

but asynchronous, have wait until script loaded use -

var js = document.createelement("script");  js.type = "text/javascript"; js.src = "path_to_the_file.js";  js.onload = function() {  //code using script here };  document.body.appendchild(js); 

Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -