view raw
Rajeev Rajeev - 5 months ago 53
Javascript Question

Embed js file in another

How to embed the following inside a js file

<script src=""></script>


You can not embed a JavaScript file in another. But you can load more JavaScript files in dynamically with a function such as this one.

function loadJS(file) {
    // Grab the head element
    var head = document.getElementsByTagName('head')[0];

    // Create a script element
    var script = document.createElement('script');

    // Set the type
    script.type = 'text/javascript';

    // Set the source file
    script.src = file;

    // Add the script element to the head