DCSIMG
Ever forgot “alert()” when deployed to production - Pini Dayan

Pini Dayan

The best thing about a boolean is even if you are wrong, you are only off by a bit.

Ever forgot “alert()” when deployed to production

As developers we often forget to remove debug code on the client side such as “alert” calls , “debugger” statements and so on. So in order to avoid our team leader throw a chair at us here is a simple solution to this problem:

On the page startup ( page load or when ever you find it necessary) simply override the alert method like this:

Set alert to work only in debug

var originalAler = window.alert;

window.alert = function(message) {

if (Sys.Debug.isDebug) {

   originalAler(message);

}

}

What i am doing here is to save the original alert method in a variable(delegate) and when someone uses the alert message simply check if we are in debug mode (I used ASP.NET Ajax) and call the original alert.

Enjoy.

 

Comments

שלמה גולדברג (הרב דוטנט) said:

כיצד לדעת האם האפליקציה בשלבי פיתוח או שהיא בשרת - בצד הלקוח באתר " ערוץ השידורים של מכללת סלע "

# December 21, 2010 6:50 PM

no said:

sometime we need alert ain't it (some alerts are real! )

what i generally do is write to console window and kill logging in production. it works with both firebug console and IE using developertoolbar.

# May 6, 2011 10:31 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: