5,316,870 members and growing! (18,890 online)
Email Password   helpLost your password?
Web Development » Client side scripting » General     Beginner

Javascript Error Blocker

By AliSufyan

Javascript Error Blocker
Javascript.NET 3.0, Windows, .NET, .NET 1.0, .NET 1.1, .NET 2.0, Win2K, WinXP, Win2003, Vista, ASP.NET, VS.NET2002, VS.NET2003, VS2005, Visual Studio, Dev

Posted: 3 Oct 2007
Updated: 3 Oct 2007
Views: 5,910
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
27 votes for this Article.
Popularity: 4.67 Rating: 3.27 out of 5
7 votes, 25.9%
1
3 votes, 11.1%
2
0 votes, 0.0%
3
3 votes, 11.1%
4
14 votes, 51.9%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

This is all about Error Stopping, do not mix it up with Error Blocking. But it does fantastic job in blocking any javascript related errors to come in your web page.

Background

The Story start as i was developing a website. It had extensive use of AJAX and asyncronous calls to web services. The main requirement was to make it cross browser compliant. To do this extensive javascript was used. Now change is a sure thing to come, so it happened. And on some forms, which were working fine, javascript errors start coming. Obviously they were not related to main program. They were coming due to change in website design, addition of fields on some forms. If i have been started to remove those, it could take a year to do so. Then i used the code below and it solved my problems. Now not a single error comes on any of my webpage, and functionality is also working out great.

Using the code

What we have to do is that just copy the code below in Head or Body section of our webpage. And leave the rest to it. Toggle track_errors to 0 or 1. 0 means Error Blocker is off and 1 means it is on. In the code snippet below i have turned Error blocking to on status.

<script language="javascript">
var track_errors=1;
function noError()
{
  if (track_errors==1)
     {
        return true;
     }
}
window.onerror = noError;
</script>

Option above is page level.If you want to make this option global then alternate way is to create a file named validate.js and copy the following code in it:

var track_errors=1;
function noError()
{
  if (track_errors==1)
     {
        return true;
     }
}
window.onerror = noError;

and reference it in your page as

<script src="validate.js" type="text/javascript"></script>

One thing to keep in mind is that use it after your development is done. As there may be crucial javascript functions that needs to be tested or included. If error comes in those then you will not be able to track those.

Points of Interest

A Great Error Blocker. Works for me everytime. Though a small piece of code. But if you like it, Please do vote for me on this.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

AliSufyan



Occupation: Web Developer
Location: Pakistan Pakistan

Other popular Client side scripting articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 11 of 11 (Total in Forum: 11) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralA better waymemberNick Taylor7:24 9 Oct '07  
Generalwhat about try / catch ?memberBrian Roberts1:07 9 Oct '07  
GeneralError is still comingmemberJigar K Oza21:31 4 Oct '07  
AnswerRe: Error is still comingmemberyashmak20:21 9 Oct '07  
GeneralNOT a good idea!!!memberghmcadams9:23 4 Oct '07  
AnswerRe: NOT a good idea!!!memberCode Monkey12:12 8 Oct '07  
GeneralRe: NOT a good idea!!!memberSeanKinsey23:16 8 Oct '07  
GeneralRe: NOT a good idea!!!memberAliSufyan4:36 18 Oct '07  
GeneralRe: NOT a good idea!!!memberthany.org22:45 15 Nov '07  
GeneralVery Nicemembermerlin9814:25 4 Oct '07  
GeneralRe: Very NicememberAliSufyan22:43 4 Oct '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 3 Oct 2007
Editor:
Copyright 2007 by AliSufyan
Everything else Copyright © CodeProject, 1999-2008
Web19 | Advertise on the Code Project