Sometimes in our JavaScript code we use bulit-in console to view information, errors, etc. But when we close the Firebug then we see the JS errors. Why? Because there is no object window.console. So, what to do? Just create console object and create empty object for all console methods.

My code, which I use:

 * Firebug console
 * If not available then add empty method

var isFirebug = false;

if(typeof window.console != 'undefined')
    for (var obj in window.console)
        if (typeof window.console[obj] != 'undefined')
            isFirebug = true;

if (!isFirebug)
    var names = [
                "assert", "clear", "count", "debug", "dir", "dirxml", "error", "exception",
                "group", "groupCollapsed", "groupEnd", "info", "log", "memoryProfile", "memoryProfileEnd",
                "profile", "profileEnd", "table", "time", "timeEnd", "timeStamp", "trace", "warn"

    window.console = {};
    var i = names.length;
        window.console[ names[i] ] = function() {};


You can leave a response, or trackback from your own site.

Before you add comment see for rules.

Leave a Reply

Your email address will not be published. Required fields are marked *