Stubbing console for older versions of Internet Explorer

Author: Steven Neiland
Published:

Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

As much as we wish it would go away and die quietly in a corner, sometimes you still have to provide at least minimal support for older versions of Internet Explorer.

One of the problems with older IE is that it did not support console functions such as log and group. This would have the nasty consequence of causing your javascript to break if you forgot to take out any of these debugging functions from your code.

To guard against this I include this code snippet in my javascript utility scripts.

if( typeof console == "undefined" ){
      console = {
            log: function() {},
            group: function () {},
            error: function () {},
            warn: function () {},
            groupEnd: function () {}
      };
}

Reader Comments

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain advertisments or appear to be created for the purpose of link building, will not be published.

Archives Blog Listing