Alternate way to load javascript counter script
<p>I am trying to load the statcounter script from my custom js file. The original script looks like this:</p>

<pre><code>&lt;html&gt;
&lt;head&gt;...&lt;/head&gt;
&lt;body&gt;
...
&lt;script type="text/javascript"&gt;
var sc_project=11111111;
var sc_invisible=1;
var sc_partition=11111111;
var sc_click_stat=1;
var sc_security="11111111";
&lt;/script&gt;&lt;script type="text/javascript" src="http://www.statcounter.com/counter/counter_xhtml.js"&gt;&lt;/script&gt;
...
&lt;/body&gt;&lt;/html&gt;
</code></pre>

<p>The code seems to set the variables, then loads the counter script which reads the values of the variables and does its job.
I'm trying to call the counter script like this:</p>

<pre><code>// file: counters.js
function CounterFromStatCounter() {
  sc_project=11111111;
  sc_invisible=1;
  sc_partition=11111111;
  sc_click_stat=1;
  sc_security="11111111";

  var oHead = document.getElementsByTagName('HEAD').item(0);
  var oScript= document.createElement("script");
  oScript.type = "text/javascript";
  oScript.src="http://www.statcounter.com/counter/counter_xhtml.js";
  oHead.appendChild( oScript);
}

 // main page
&lt;html&gt;
&lt;head&gt;
...
&lt;script type="text/javascript" src="counters.js"&gt;&lt;/script&gt;
...
&lt;/head&gt;
&lt;body&gt;
...
&lt;script type="text/javascript"&gt;
  CounterFromStatCounter();
&lt;/script&gt;
...
&lt;/body&gt;&lt;/html&gt;
</code></pre>

<p>The code seems to work: the <strong>script</strong> element that references the statcounter script appears in the <strong>head</strong> section as it should, but no visits are recorded - this means that the variables set in my script cannot be accesed by the counter script.</p>

<p>What am I doing wrong? </p>
