Alex Rivera | Logout

What's the correct way to write to the script console (console.log) in IE?

Asked 2010-12-01T12:42:35.743
17

I have this substitute for console.log defined in document.ready():

$(document).ready(function(){
  console.log("doc ready");
  if(typeof console === "undefined"){
    console = { log: function() { } };
  }
}

I thought IE was supposed to have this function available but, when I include the call above

  console.log("doc ready");

the output appears in the Firefox console but not in IE - in fact IE script execution breaks completely at this point.

What's the correct way to write to the console in IE?

Edit
Report

2 Answers

2

Here's what I use to failover to firebug lite if there is no console available. This guarantees you'll get console of some description although they all work slightly differently so be wary.

function attachConsole(force) {
  if(force || typeof console === "undefined"){
    var head= document.getElementsByTagName('head')[0];
    var script= document.createElement('script');
    script.type= 'text/javascript';
    script.src= 'http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js';
    head.appendChild(script);
    return true;
  }
return false;
}
answered 2010-12-01T14:02:30.463
0

console is for firebug.

You will have to install firebug lite to enable writing to console in IE.

answered 2010-12-01T12:46:33.853

Your Answer