0

Chrome, FireFox and Safari can all log to the console without having the developer tool view open. However, IE 8 and 9 (not sure about 10) cannot, as console will be undefined without opening the developer tool first.

Is there any workaround for this? External JavaScript library?

MLister
  • 8,552
  • 16
  • 56
  • 86

2 Answers2

1

I'm not sure of any library that will help you with this in IE but you could encapsulate your logging within a method so that it will operate normally in IE when not in developer mode.

function log(val){
  if(console.log){
    console.log(val);
  }
}
Kevin Bowersox
  • 88,138
  • 17
  • 142
  • 176
  • Store the `val` in the DOM or inside a global for later retrieval perhaps, as a fallback for missing `console.log`, with `console = { 'log': function(val) { fallbacklog.push(val); } }` – soulseekah Nov 25 '12 at 20:20
  • @kmb385, or this: `window.console && console("log something here");` – MLister Nov 25 '12 at 20:23
1
window.console = window.console || {log: function(){}};

THis wont let you access the logs, but it will avoid null pointer errors.

goat
  • 29,650
  • 7
  • 65
  • 92