console.log()已定义但未登录IE - 空控制台 [英] console.log() is defined but doesn't log in IE - empty console
问题描述
Internet Explorer(8和9)页面上的Javascript 打开开发人员工具到达 console.log()
,已定义 - 但实际日志中没有任何内容。
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.
尝试的事情:
- 使用
alert()
仔细检查console
是否已定义并且console.log
是一个函数。 - 使用
alert()进行检查
s之前和之后代码确实到达console.log()
行, - 检查任何IE回退的代码,如
if(ie){console = {log:function(){}}}
,删除指向库的链接并检查代码片段以提及console
- 检查IE的设置并启用与调试相关的任何内容
- 通过加载第三方页面来检查IE是否已损坏
console.log()
s(例如 http://jsbin.com 记录in它和跑步者) - 交换
控制台
forwindow.console
- Double-checking with
alert()
s thatconsole
is defined and thatconsole.log
is a function. - Checking with
alert()
s before and after that the code does reach theconsole.log()
line, - Checking code for any IE fallbacks like
if(ie){console={log:function(){}}}
, removing links to libraries and checking code snippets for mentions ofconsole
- 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
forwindow.console
因此控制台在那里并且处于活动状态,但实际控制台中没有显示控制台消息(在脚本选项卡或控制台上tab)。
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).
还有什么可以阻止 console.log()
实际记录任何内容,即使开发人员工具是open和 console.log
是一个已定义的函数吗?
What else could stop console.log()
from actually logging anything, even when Developer Tools is open and console.log
is a defined function?
推荐答案
罪魁祸首在这种情况下,结果证明是 firebug lite 。
The culprit in this case turned out to be, of all things, firebug lite.
我的测试开发页通常包括这个(具有讽刺意味)援助某些IE中的调试类型:
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.
警告警报(console.log);
显示firebug lite 之前和之后更改console.log函数从本机代码到:
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.
如果不涉及Firebug Lite,IE中的 alert(console.log);
会给出:
Without Firebug Lite getting involved, alert(console.log);
in IE gives this:
function log() {
[native code]
}
...并且如果f12开发工具处于打开状态,则执行常规日志记录,如果不是,则执行崩溃。
...and does its usual trick of logging if f12 Dev Tools is open and crashing if it isn't.
这篇关于console.log()已定义但未登录IE - 空控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!