Rajeev Rajeev - 1 year ago 112
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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download