Is there a way to log to console without breaking code under IE?

前端 未结 6 544
后悔当初
后悔当初 2021-02-05 18:50

I\'m trying to use console.log to put some logging into the javascript side of my program. I noticed, though, that unless the dev console is open in IE, JS basically stops worki

6条回答
  •  后悔当初
    2021-02-05 19:42

    IE has its own console, and you wont want to override console if you're using firebug lite. Just make sure that console exists when log gets called:

    if (window.console) console.log('foo bar baz', fizz, buzz);
    

    Better yet, use && to shortcut:

    window.console && console.log('foo bar baz', fizz, buzz);
    

提交回复
热议问题