Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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

like image 385
vondip Avatar asked Mar 14 '11 16:03

vondip


2 Answers

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 the returnValue property of the event object to true or simply return true 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 returning true. 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

like image 181
T.J. Crowder Avatar answered Sep 28 '22 14:09

T.J. Crowder


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.

like image 31
JasCav Avatar answered Sep 28 '22 14:09

JasCav