console.log usa alertas en ie9 con herramientas de desarrollador abiertas

I am using IE9 and trying to debug some javascript. I read all over the place that console.log() will actually log to the console rather than puking up alerts when developer tools are open.

However, I have developer tools open and console.log is still giving alerts. What am I missing?


  • Browser Mode: IE9 Compat Mode
  • Modo de documento: estándares IE8

preguntado el 01 de febrero de 12 a las 22:02

You'll have to provide a test case, because I have nunca (even with developer tools in IE6) had console.log() crear un alert(). From all my experience, if tools aren't open, console.log() throws an error because console is undefined unless the tools are open. -

3 Respuestas

I would look to see if console.log is being redefined somewhere in your JS.

Respondido 28 Abr '12, 19:04

console.log() no se alert() anything ... I think you are using some custom console.log-function in your code. However I'd always suggest to use those tiny functions which are shipped with 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={});}}());

Include them, use them and you'll not have any errors caused by your debugging output in IE.

Respondido 30 Abr '12, 12:04

Puede ser que console.log has been rewritten by some script on the page. I'd test if this alert behavior appeared on all sites or just this one you are currently testing. (If it does happen everywhere, maybe console.log is being rewritten by a browser add-on.)

Intenta usar console.warn instead (or even console.error, in a pinch) -- perhaps that will still behave as expected. It's a nice sanity check, and it can still get you debugging output if you never get console.log trabajando.

Respondido 30 Abr '12, 22:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.