Wednesday 10 April 2013

Console.log for IE

Using of Alert to loop/debug through the code is sometimes annoying for a developer as IE does not come with *Console*. Below code snippet will take care of *Consle* object an IE, it works in two ways. - If you have debugger open than it will log the information on IE console. - If you do not have IE debugger open than it will use ALERT the log the information.
var alertFallback = true;
if (typeof console === "undefined" || typeof console.log === "undefined") {
  console = {};
  if (alertFallback) {
      console.log = function(msg) {
           alert(msg);
      };
  } else {
      console.log = function() {};
  }
}

  • Case -1 . Without opening Debugger
In this case it will display logger messages in alert.

      



  • Case-2 With Debugger 
In this case it will display logger message in the IE debugger console