attaching a script dynamically using jQuery
<p>I have a problem which have been troubling me for the last few days. I have to implement tracking to my website simply by adding a script tag as shown below.</p>

<pre><code>&lt;script src="domain"&gt;
</code></pre>

<p>However I need to attach the script tag once a javascript event is fired. I made some research and discovered this can be achieved using jQuery .getScript() function. Sample code shown below.</p>

<pre><code>$('body').bind("success", function(e, data) {
    // Call for the tracking scipt here
    $.getScript("domain", function() {});
});
</code></pre>

<p>My problem is that the loaded script contains the below code:</p>

<pre><code>document.write(&lt;img src='domain'/&gt;); 
</code></pre>

<p>Unfortunately this code is not executed, (I am guessing since the DOM is already loaded at the time I am attaching the script, the document.write() function will not work.) I also tried using native javascript code as shown below to no avail.</p>

<pre><code>var body = document.getElementsByTagName("body")[0];         
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "domain";
body.appendChild(script);
</code></pre>

<p>At the moment I have managed to achieve this by placing the scipt tag in a seperate page and then load the page in an invisible iFrame from the fired JS event. I don't really like this idea, so any help would be appreciated.</p>
