My guess is that in your DOM-only solution you did something like:
var script = document.createElement('script');
script.src = something;
//do stuff with the script
First of all, that won't work because the script is not added to the document tree, so it won't be loaded. Furthermore, even when you do, execution of javascript continues while the other script is loading, so its content will not be available to you until that script is fully loaded.
You can listen to the script's load
event, and do things with the results as you would. So:
var script = document.createElement('script');
script.onload = function () {
//do stuff with the script
};
script.src = something;
document.head.appendChild(script); //or something of the likes
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…