Calling a function inside the body, from an external JS file which is dynamically loading
<p>I have an external JS file:</p>

<pre><code>console.log("DEBUG1");

function Function1() {
    console.log("DEBUG2");
}

function Function2() {
    console.log("DEBUG3");
}
</code></pre>

<p>I want to load this JS file dinamically in the head and then call the function Function1() inside the body, before the body onLoad event occurs. <a href="http://lucaghio.webege.com/Prova5/" rel="nofollow">Here</a>, I've tried <a href="http://ntt.cc/2008/02/10/4-ways-to-dynamically-load-external-javascriptwith-source.html" rel="nofollow">all these solutions</a>: only the first one works, but I would like to avoid it.</p>

<p>For example, solution 2 is:</p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;script type="text/javascript"&gt;&lt;/script&gt;
        &lt;script type="text/javascript"&gt;
            document.getElementsByTagName("head")[0].getElementsByTagName("script")[0].src = "JS.js";
        &lt;/script&gt;
    &lt;/head&gt;

    &lt;body onLoad="javascript:Function2();"&gt;
        &lt;script type="text/javascript"&gt;
            Function1();
        &lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>How can I solve this (without using solution 1)?</p>
