Does IE9 support console.log, and is it a real function?

后端 未结 7 983
醉话见心
醉话见心 2020-11-22 06:16

In which circumstances is window.console.log defined in Internet Explorer 9?

Even when window.console.log is defined, window.console.

7条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 06:48

    A simple solution to this console.log problem is to define the following at the beginning of your JS code:

    if (!window.console) window.console = {};
    if (!window.console.log) window.console.log = function () { };
    

    This works for me in all browsers. This creates a dummy function for console.log when the debugger is not active. When the debugger is active, the method console.log is defined and executes normally.

提交回复
热议问题