You can use the onloadscript element event for most browsers and use the callback argument:
Edit: You really cannot stop code execution when loading scripts this way (and synchronous Ajax requests are a bad idea in most cases).
, , , : Two.js Three.js, , :
loadScript('http://example.com/Two.js', function () {
loadScript('http://example.com/Three.js', function () {
});
});
:
function loadScript(url, callback) {
var head = document.getElementsByTagName("head")[0],
script = document.createElement("script"),
done = false;
script.src = url;
script.onload = script.onreadystatechange = function(){
if ( !done && (!this.readyState ||
this.readyState == "loaded" || this.readyState == "complete") ) {
done = true;
callback();
script.onload = script.onreadystatechange = null;
head.removeChild( script );
}
};
head.appendChild(script);
}
IE onreadystatechange.