Rajeev Rajeev - 10 months ago 73
Javascript Question

Embed js file in another

How to embed the following inside a js file

<script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>

Answer Source

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