Suppressing JavaScript errors

What is the most annoying thing you cant think of? Well ok, JavaScript error aren’t that annoying but nobody likes them. What we need is a simple script that stops all the JavaScript erros from appearing. This is a pretty simple script which is short so lets dive straight into the code.

<script>
function stoperror(){
return true
}
window.onerror=stoperror
</script>

Just stick the script into the head tag. Although the above alert method is invalid (no closing quotations), no errors will be generated. This script will suppress all potential errors in a page, so be sure to turn it off while test running a script.

Of course, a much better solution, is to actually write JavaScript that works.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.