• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 655
  • Last Modified:

How do you supress javascript errors?

Can javascript errors be supressed or told not show like in php? In php I can use error_reporting(0) to prevent them from being shown to users. Can that also be done in javascript?

The reason is a lot of the sites that I work on, the errors come from an outside script that you don't have access to, but also the errors are not causing any issues. But in browsers I can see the little error icons lighting up. I would like to prevent that once I've confirmed that the errors aren't causing any problems or going to slow the users viewing of the site.
3 Solutions
When you say little error icon that leads me to believe this is IE... No you cannot turn that off, the only way to get rid of it is to fix the JavaScript error.... If the user is getting a debug error you can of course turn that off, but only at their local machine, not via PHP....

The JavaScript error message means you have an error which needs to be fixed, it may not cause a problem now but when the user upgrades to a new browser it may become more of a problem...
DzynitAuthor Commented:
I use firefox, but I know both ff and ie have icons that tell you when there is an error.

Problem is the scripts with errors are not all accessible.

You can see what I mean here: http://www.oregoncosmeticlaser.com/

But I don't want to be able to supress them with php, just making the comparison because php has a code line option to supress them. I wondered if javascript had one also.
no, JavaScript does not have a suppress command since this is controlled by the web browser and not the code itself... If you use Chrome the error is suppressed but available in the development area...

Sorry, the error is suppose to alert you to a problem that needs to be corrected, not to just ignore it....  The error I see on the site you listed above is a common one and very easy to fix with either a null check before using the variable or declaring it..
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

You *could* use the try...catch block, that could catch logical errors(but usually not  a syntax error).  If you need to fallback if there is an error, this is how you can.  However, if you are using it simply to mask bad coding, you should fix the code.

try {
   doThis();  //assuming doThis isn't defined anywhere
catch(exception) {
   //alert(exception.message);  //doesn't work in all browsers if I recall
   alert('Something borked!');

Open in new window

DzynitAuthor Commented:
One last question if it's common and an easy fix: since it's coming from ajax.google, how do I fix the error?

Warning: reference to undefined property jQuery.cache[id][name]
Source File: http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js
Line: 19
Interesting, IE8 shows a different errors....

Webpage error details

Message: 'jQuery' is null or not an object
Line: 1
Char: 1
Code: 0
URI: http://www.oregoncosmeticlaser.com/wp-content/themes/oregoncosmeticlaser/js/jqueryslidemenu.js

sounds like jQuery was never declared, I would suggest turning on a JavaScript debugger and stepping through your JavaScript before it calls the Google JavaScript ..

how about handling it this way?

    <script type="text/javascript">
    window.onerror = function (msg, url, num) {
        alert(msg + ' || ' + url + ' || ' + num);
        return true;
	<script type="text/javascript" src="helloworld.js"></script>
    <script type="text/javascript">

Open in new window


Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now