var oScript = document.createElement( 'script' ); oScript.type = 'text / javascript' ; oScript.src = "xx.js" ; / * **スクリプトタグのonloadおよびonreadystatechangeイベント ** IE6 / 7/8 onreadystatechangeイベントをサポート ** IE9 / 10はonreadystatechangeおよびonloadイベントをサポート ** Firefox / Chrome / Operaはonloadイベントをサポート * / // IE8以下のブラウザーを 判断var isIE =!-[1 、]; if (isIE){ oScript onreadystatechange = function (){
//つまり、404readyStateがロードされているか完了している 場合(これは.readyState == 'loaded' || this .readyState == 'complete' ){ callback(); } } } else { // IE9 及以上浏览器、Firefox、Chrome、オペラ oScript.onload = function (){ callback(); }
oScript.onerror = function (){
//エラーコールバック
}
}
var head = document.getElementsByTagName( 'head')[0 ];
head.appendChild(oScript);