console.log在ie9中使用警报,并打开开发人员工具

时间:2012-02-01 22:37:02

标签: javascript console internet-explorer-9

我正在使用IE9并尝试调试一些javascript。我在console.log()实际登录到控制台的地方读到了,而不是在开发人员工具打开时发出警报。

但是,我打开了开发人员工具,console.log仍在发出警报。我错过了什么?


  • 浏览器模式:IE9 Compat Mode
  • 文档模式:IE8标准

3 个答案:

答案 0 :(得分:1)

我想看看是否在JS中的某个地方重新定义了console.log。

答案 1 :(得分:0)

console.log()不会alert()任何内容......我认为您在代码中使用了一些自定义的console.log-function。但是我总是建议使用html5boilerplate附带的那些小功能:

// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function f(){ log.history = log.history || []; log.history.push(arguments); if(this.console) { var args = arguments, newarr; args.callee = args.callee.caller; newarr = [].slice.call(args); if (typeof console.log === 'object') log.apply.call(console.log, console, newarr); else console.log.apply(console, newarr);}};

// make it safe to use console.log always
(function(a){function b(){}for(var c="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),d;!!(d=c.pop());){a[d]=a[d]||b;}})
(function(){try{console.log();return window.console;}catch(a){return (window.console={});}}());

包含它们,使用它们,并且IE中的调试输出不会导致任何错误。

答案 2 :(得分:0)

可能是console.log已被页面上的某些脚本重写。我会测试这个alert行为是出现在所有网站上还是仅出现在您正在测试的网站上。 (如果它确实发生在任何地方,可能会被浏览器插件重写console.log。)

尝试使用console.warn代替(甚至console.error,在紧要关头) - 也许这仍然会按预期运行。这是一个很好的完整性检查,如果你从未让console.log工作,它仍然可以让你调试输出。

相关问题