console.log() is defined but doesn't log in IE - empty console

时间秒杀一切 提交于 2019-12-23 18:49:10

问题


Javascript on a page in Internet Explorer (8 and 9) with Developer Tools open reaches console.log(), which is defined - but nothing appears in the actual log.

Things tried:

  • Double-checking with alert()s that console is defined and that console.log is a function.
  • Checking with alert()s before and after that the code does reach the console.log() line,
  • Checking code for any IE fallbacks like if(ie){console={log:function(){}}}, removing links to libraries and checking code snippets for mentions of console
  • Checking IE's settings and enabling anything relating to debugging
  • Checking that IE isn't broken by loading a 3rd party page with console.log()s (e.g. http://jsbin.com logs "init" and "runner")
  • Swapping console for window.console

So the console is there and active, but no console messages show up in the actual console (on either the Script tab or the Console tab).

What else could stop console.log() from actually logging anything, even when Developer Tools is open and console.log is a defined function?


回答1:


The culprit in this case turned out to be, of all things, firebug lite.

My test dev pages often include this to (ironically) aid certain types of debugging in IE:

<!--[if IE]>
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script>
<![endif]-->

Since it appears in text editors as a comment, it's easy to accidentally overlook.

Alerting alert(console.log); before and after shows firebug lite changes the console.log function from the native code to this:

function(){return f.apply(c,arguments)}

...which for some reason (at the moment, here) then does nothing.

Without Firebug Lite getting involved, alert(console.log); in IE gives this:

function log() {
[native code]
}

...and does its usual trick of logging if f12 Dev Tools is open and crashing if it isn't.



来源:https://stackoverflow.com/questions/21321872/console-log-is-defined-but-doesnt-log-in-ie-empty-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!