Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript include js file

function loadScript( url, callback ) {
  var script = document.createElement( "script" )
  	  script.type = "text/javascript";
      script.src = url;
 	  script.onload = function() {
     	callback()
      };
     document.head.appendChild(script); 
}
// call the function...
loadScript("js/myscript.js", function() {
  alert('script ready!'); 
});
Comment

include js to js

var imported = document.createElement('script');
imported.src = '/path/to/imported/script';
document.head.appendChild(imported);
Comment

include js to js

<script type="module">
  import { hello } from './hello.mjs'; // Or it could be simply `hello.js`
  hello('world');
</script>

// hello.mjs -- or it could be simply `hello.js`
export function hello(text) {
  const div = document.createElement('div');
  div.textContent = `Hello ${text}`;
  document.body.appendChild(div);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: axios middleware 
Javascript :: document queryselectorall and map javacript 
Javascript :: string to date js 
Javascript :: how to convert set to a string in js 
Javascript :: react render component after data loaded 
Javascript :: string normalize javascript 
Javascript :: Use Multiple Conditional Ternary Operators Javascript 
Javascript :: js console log multiple 
Javascript :: javascript list has item 
Javascript :: form.select not working react bootstrap 
Javascript :: get average and sum javascript 
Javascript :: npm i postman 
Javascript :: js stairs algorithm 
Javascript :: link to another page and achor react 
Javascript :: promise.all vs promise.allsettled 
Javascript :: set input value vanilla js 
Javascript :: get element by xpath 
Javascript :: chunk an array 
Javascript :: fs.readfile 
Javascript :: convert arrow function to normal function javascript 
Javascript :: angular build production 
Javascript :: reset form input react 
Javascript :: parse string to int nodejs 
Javascript :: json load 
Javascript :: js string methods 
Javascript :: js object clear 
Javascript :: redux dispatch no connect 
Javascript :: base64 encoded data to object in javascript 
Javascript :: my loader is continously loading js 
Javascript :: start pm2 node process with flags 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =