As you are returning true
from the function, the default action of the link is allowed and the browser goes on to navigating to the page.
Exactly what happens with changes to the document and queued requests may differ, as it's up to the implementation of the browser to do something that is reasonable, and both requesting the script and not doing it are within what's reasonable.
As you are navigating away from the page, you can't expect the browser to actually do anything more in the current page. Some browsers may go on as nothing happens until the new page starts to arrive, some may suspend some actions as they would request data for a page that isn't supposed to be there any more when the response arrives.
To make it work in any browser you should return false
from the function to keep the link from being activated, and wait for the script to load before you navigate to the new page.
Edit:
Add a paramter to the function to handle the URL:
function myFunction(url, atlasTrackingURL)
Use the onload
event to navigate to the URL when the script has loaded:
var script = document.createElement("script");
script.type = "text/javascript";
script.onload = function() {
window.location.href = url;
};
script.src = atlasURL;
document.getElementsByTagName("head")[0].appendChild(script);
return false;
Return the result in the event handler to stop the link from being activated:
<a href="http://www.microsoft.com" onclick = "return myFunction(this.href, 'http://view.atdmt.com/jaction/adoakb_PiggybackJSTest_1')">Test - Click Me</a>