Tuesday, March 13, 2012

Generic Utility for Console Logging



I very much belief that you might have used the following statement in your web development:
console.log(text);


Again the browser must have been firefox or Safari or chrome.
How about the tackling the same in IE ?

I have used a small hack to skip logging in IE and all those browser which does not support console directly.


Here is the code:

utilities = {
    logMessage: function (text) {
        if ((window['console'] !== undefined)) {
            console.log(text);
        }
     }
}

Usage:
utilities.logMessage (" .... message to log...");

No comments:

Post a Comment