Including a JavaScript File
We can include a javascript file dynamically like other languages in your javascript code. Here is the source code to include a javascript file dynamically.
-
-
<script language="JavaScript">
-
-
function include_js(file)
-
-
{
-
-
var include_file = document.createElement(’script’);
-
-
include_file.type = ‘text/javascript’;
-
-
include_file.src = file;
-
-
document.getElementsByTagName(‘head’)[0].appendChild(include_file);
-
-
}
-
-
/* include your file */
-
-
include_js(‘myscript.js’);
-
-
</script>
Here I have used the DOM to create the script object.







