Wednesday 30 November 2016

Create custom log for IE 8 in Javascript

As we know console is not exists in IE without inspecting in developer mode. So our simple code will run on IE 8 . If console  will available it will log or else it will alert message if fallback set to true.


(function() {
    logenabled = true,
 fallbackalert = true,
    _console = {
        log: function (val) {
            if (console != null && console != 'undefined' && logenabled)
   {
    console.log("My console: " + val);
   }
   else
   {
    if(fallbackalert){
     alert(val);
    }
   }
        }
    }
}());

_console.log('Data');