由于各個(gè)瀏覽器對js代碼的異步執(zhí)行函數(shù)的支持不一樣
window.execScript() 只支持IE瀏覽器
eval() 雖然支持各個(gè)瀏覽器,但是卻不能在全局執(zhí)行
解決的方法是利用javascript里面有一個(gè)改變上下文環(huán)境的關(guān)鍵字with .
把GetJsFile方法改成如下:
function getJsFile(url, callBack){
var XH = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject('Msxml2.XMLHTTP');
XH.open('get',url,true);
XH.onreadystatechange = function(){
if(XH.readyState == 4 && XH.status == 200){
with ( window )eval(XH.responseText);
//if(window.execScript) window.execScript(XH.responseText);
//else eval.call(window, XH.responseText);
with ( window )eval(callBack);
}
}
XH.send('');
}