IE - prevent errors from being shown in IE
I am developing a web application. My application works great on chrome and firefox, but from some reason is rises some errors in IE. Even though several errors arise, the application can still run smoothly, with no apparent problem.
I'd like 开发者_Python百科to hide the errors from the end user, as currently he is presented with a small icon that says an error occurred.
How can I achieve this?
Thank you
The best thing to do, by far, is figure out where the code is causing the error and fix that.
Update: The below is true for IE8, but not IE9 or IE11 (and so probably not true for IE10):
Because this is specifically happening in IE, you could use window.onerror
to handle (suppress) them if they're runtime (not compilation) errors, which from your comment on another answer it sounds like they are. From that link:
To suppress the default Internet Explorer error message for the
window
event, set thereturnValue
property of theevent
object totrue
or simply returntrue
in Microsoft JScript.The
onerror
event fires for run-time errors, but not for compilation errors. In addition, error dialog boxes raised by script debuggers are not suppressed by returningtrue
. To turn off script debuggers, disable script debugging in Internet Explorer by choosing Internet Options from the Tools menu. Click the Advanced tab and select the appropriate check box(es).
Example:
This code causes an error (because I'm trying to dereference undefined
):
document.getElementById('theButton').onclick = function() {
var d;
display(d.foo);
};
Live copy
But if we add this, the error is suppressed because we tell IE we handled it:
window.onerror = function() {
// Return true to tell IE we handled it
return true;
};
Live copy
As far as I know, there is no real way to do this because you would then be controlling the browser (AKA the application) and this would be a bad thing. The user can manually turn off those errors, or you can see if you can fix your JavaScript. But, other than those two solutions, I think you're out of luck.
Fix the errors - most of the time, they would be something trivial that only IE trips on. For those cases, fixing the problems found by JSLint helps with 90% of the stuff: http://www.jslint.com/lint.html
精彩评论