等しい「ロードされた」または「完全な」 、Internet Explorerで。
スクリプトがロードされたことを通知される前に、宣言されていないオブジェクトや関数、プロパティにまだアクセスしようとしていない可能性があります。
var appendScript = function(parent, scriptElt, listener) {
// append a script element as last child in parent and configure
// provided listener function for the script load event
//
// params:
// parent - (DOM element) (!nil) the parent node to append the script to
// scriptElt - (DOM element) (!nil) a new script element
// listener - (function) (!nil) listener function for script load event
//
// Notes:
// - in IE, the load event is simulated by setting an intermediate
// listener to onreadystate which filters events and fires the
// callback just once when the state is "loaded" or "complete"
//
// - Opera supports both readyState and onload, but does not behave in
// the exact same way as IE for readyState, e.g. "loaded" may be
// reached before the script runs.
var safelistener = catchError(listener,'script.onload');
// Opera has readyState too, but does not behave in a consistent way
if (scriptElt.readyState && scriptElt.onload!==null) {
// IE only (onload===undefined) not Opera (onload===null)
scriptElt.onreadystatechange = function() {
if (scriptElt.readyState === "loaded" ||
scriptElt.readyState === "complete") {
// Avoid memory leaks (and duplicate call to callback) in IE
scriptElt.onreadystatechange = null;
safelistener();
}
};
} else {
// other browsers (DOM Level 0)
scriptElt.onload = safelistener;
}
parent.appendChild(scriptElt);
};
ニーズに適合させるために、あなたがキャッチし、エラーを記録するために、リスナーをラップcatchErrorへの呼び出しを置き換えることがあります。ここでは
は私の
Javascript library, bezen.orgにモジュール
bezen.dom.jsから抽出された例の関数であり、 、および修正機能を使用します。あなたは、外部スクリプトを編集することができるように見えるので
var appendScript = function(parent, scriptElt, listener) {
// append a script element as last child in parent and configure
// provided listener function for the script load event
//
// params:
// parent - (DOM element) (!nil) the parent node to append the script to
// scriptElt - (DOM element) (!nil) a new script element
// listener - (function) (!nil) listener function for script load event
//
// Notes:
// - in IE, the load event is simulated by setting an intermediate
// listener to onreadystate which filters events and fires the
// callback just once when the state is "loaded" or "complete"
//
// - Opera supports both readyState and onload, but does not behave in
// the exact same way as IE for readyState, e.g. "loaded" may be
// reached before the script runs.
var safelistener = function(){
try {
listener();
} catch(e) {
// do something with the error
}
};
// Opera has readyState too, but does not behave in a consistent way
if (scriptElt.readyState && scriptElt.onload!==null) {
// IE only (onload===undefined) not Opera (onload===null)
scriptElt.onreadystatechange = function() {
if (scriptElt.readyState === "loaded" ||
scriptElt.readyState === "complete") {
// Avoid memory leaks (and duplicate call to callback) in IE
scriptElt.onreadystatechange = null;
safelistener();
}
};
} else {
// other browsers (DOM Level 0)
scriptElt.onload = safelistener;
}
parent.appendChild(scriptElt);
};
この関連の答えをチェックアウト:** [動的に追加されたスクリプトタグの読み込み順序](http://stackoverflow.com/a/38840724/2247494)** – jherax