19

I just started playing around with IE10 on Win8 and ran into problem. The developer tools console doesn't seem to work when the Document Mode is set to Standards. I've played around with both the Browser Mode and the Document Mode, and console works when Set as IE9 Standards, but setting it to simply "Standards", the default for IE10, console is undefined. Any ideas?

This is not a duplicate. When testing, developer console is open. Switching Doc mode to IE9 standards and reloading displays console output as expected. Switching back to IE10 standards displays no console output. Debugging shows console is undefined which thus sets console.log to an empty function to handle the undefined. I'm curious as to why the console is undefined when in IE10 standards mode.

I'm running Win8 in a VirtualBox. My page is HTML4 markup with appropriate doctype.

James
  • 201
  • 1
  • 2
  • 7
  • 9
    You must have the developer tools open *when the page loads*. See [here](http://stackoverflow.com/questions/10415519/does-ie9-enable-something-when-using-developer-tools/10415712#10415712) – jbabey Feb 04 '13 at 20:52
  • Developer Tools are open when page loads. – James Feb 04 '13 at 21:07
  • So you open the page, press F12 to open the developer tools, then press F5 to reload the page, and the `console` still shows as `undefined`? – jbabey Feb 04 '13 at 21:10
  • 1
    yes. If i switch doc mode to IE9 Standards, console is not undefined. Switching back to Standards, console is undefined – James Feb 04 '13 at 21:15
  • I wish I had IE10 to hand to try this out - it sounds completely nuts. – Spudley Feb 04 '13 at 22:33
  • 2
    @Spudley which would be standard IE-behavior... – Christoph Feb 05 '13 at 13:30
  • no freaking idea on this one. Can not reproduce, but seems standard IE behaviour :) BTW I like the '... console is not undefined' double negation.:) – roel Feb 05 '13 at 13:41
  • 1
    I'm seeing the same issue. IE10 Standards=not working. IE10 in IE9 Standards mode=working – Tim Bailey Jul 03 '13 at 00:27

2 Answers2

7

The reason why console.log(); is undefined is because that's how standards mode works. IE 8 has a compatibility mode that literally turns it into IE 7, removing all understanding of features added to IE 8. The console was added in IE 10, so by running it in standards mode, it would make sense for it to throw errors.

<head>
    <title>Force IE 10</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>

This meta tag up here will force IE to run in the most recent version you have installed (disabling standards and compatibility mode). This is the only way to have your console defined in IE 10 in standards mode — by disabling standards mode.

Andrew
  • 546
  • 4
  • 17
  • 2
    Microsoft explains that IE=edge "is functionally equivalent to using the HTML5 doctype" so is enough. See http://msdn.microsoft.com/en-US/library/jj676915.aspx – tanguy_k Sep 27 '13 at 15:08
  • 5
    On what planet does that "make sense"? What makes sense is that microsoft produces a horrid browser that never complies to actual "standards" – Andrew Rhyne Dec 05 '13 at 09:06
  • 3
    It makes sense because of how IE 8 handles errors. It just simply crashes the rest of that javascript. Putting a `console.log()` at the beginning of a jQuery file would cause jQuery to not load on the page. Having IE 10 in standards mode gracefully exit errors would cause it to function differently than IE 8. Also, to tanguy_k, ` ` would cause IE 9 and below to default into `loose.dtd` (it might be `transitional.dtd`, I forget which) and might cause the page's CSS to break. – Andrew Dec 05 '13 at 18:01
  • Also, make sure you are not pulling cached content. Clear your cache and then turn on the Dev Tools setting "Always refresh from server" under the Cache menu. This is the only way I got this to work for me. – Neil Monroe Apr 06 '15 at 21:24
5

define it!

if (typeof console == "undefined") {
    this.console = {log: function() {}};
}

see : 'console' is undefined error for Internet Explorer

Community
  • 1
  • 1
left
  • 51
  • 4
  • It sounds like the OP is aware of this workaround, but is curious why `console.log` does not work properly in certain modes. – jahroy Mar 21 '13 at 21:29
  • This is already being done. Note "Debugging shows console is undefined which thus sets console.log to an empty function to handle the undefined." – James Apr 01 '13 at 15:21