How to suppress all JavaScript runtime errors?

Skip picture Skip · Aug 19, 2011 · Viewed 21.2k times · Source

How can I suppress all JavaScript runtime error popups, from the programmers side?

Answer

Skip picture Skip · Aug 20, 2011

To suppress all JavaScript errors there seems to be a window.onerror event.
If it is replaced as early as possible(e.g. right after the head) by a function which returns true - there will be no error popups, which is quite useful after debugging is done.

<head>
<script type="text/javascript">
    window.onerror = function(message, url, lineNumber) {  
        // code to execute on an error  
        return true; // prevents browser error messages  
    };
</script> 
...

Error Logging is possible too, as explained here