Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 417
Rajeev Avatar asked Dec 22 '22 18:12

Rajeev


1 Answers

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
    head.appendChild(script);
}
like image 62
Olical Avatar answered Dec 30 '22 16:12

Olical