Javascript: Detecting Script Load Completion
I'm dynamically adding script usign: var el = document.createElement('script'); document.getElementsByTagname('head')[0].appendChild(el); It seems neither script.onload nor docume
Solution 1:
The onload
event needs to be attached before setting the script's src
, which is what causes the script to start loading.
Example:
var el = document.createElement("script");
el.onload = function() {
// Script is loaded
}
el.src = ...
Solution 2:
I think you want something very similar to this: Trying to fire the onload event on script tag
$body.append(yourDynamicScriptElement);
yourDynamicScriptElement.onload = function() { //...
yourDynamicScriptElement.src = script;
Post a Comment for "Javascript: Detecting Script Load Completion"