我在try/catch塊中使用execScript來執行一段字符串化的JavaScript。如果execScript中的字符串有javascript錯誤,將在IE 8的catch塊中隨後重新載入頁面時返回以下錯誤:execScript在IE 8中嘗試/捕捉奇數8
'錯誤:由於錯誤80020101而無法完成操作。'
是否有任何其他方式在全球範圍內評估IE8中的JavaScript,它不會拋出類似上面那樣的通用錯誤。我知道使用eval不會工作,因爲它不會在全局上下文中評估JavaScript。
下面是一些設置爲我的代碼看起來像,FN是要計算的字符串:
// fn is defined somewhere above this code
function globalEvaluation() {
if(document.defaultView) {
document.defaultView.eval.call(undefined, fn);
} else if (document.parentWindow) {
document.parentWindow.execScript(fn);
}
}
return function() {
try {
globalEvaluation();
} catch(e) {
// do some error handling
// in IE 8 I get the 80020101 error
}
}