Net-informations.com

How to include JavaScript file into another

The old versions of Client-side JavaScript offers no built in functions to manage multiple scripts within the browser. But, it is possible to dynamically generate a JavaScript tag and append it to HTML document from inside other JavaScript code.


JavaScript file into another

example

Let's suppose you've two JavaScript files named "message.js" and "next.js" and you included only the message.js in the HTML file. If you want to call a function from next.js , you can dynamically generate a JavaScript tag and append it to HTML document from inside other JavaScript code.

Javascript File (message.js)

Javascript File (next.js)

HTML File

Here you can see the msg1() function is declared in next.js and not included in HTML file . But with the help of the Javascript function "includeFile(incFile)" you can dynamically generate a JavaScript tag and append next.js to HTML document from inside other JavaScript code.










net-informations.com (C) 2020    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About