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

后端 未结 7 888
醉话见心
醉话见心 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:41

    I know this is a very old question but feel this adds a valuable alternative of how to deal with the console issue. Place the following code before any call to console.* (so your very first script).

    // Avoid `console` errors in browsers that lack a console.
    (function() {
        var method;
        var noop = function () {};
        var methods = [
            'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
            'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
            'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
            'timeStamp', 'trace', 'warn'
        ];
        var length = methods.length;
        var console = (window.console = window.console || {});
    
        while (length--) {
            method = methods[length];
    
            // Only stub undefined methods.
            if (!console[method]) {
                console[method] = noop;
            }
        }
    }());
    

    Reference:
    https://github.com/h5bp/html5-boilerplate/blob/v5.0.0/dist/js/plugins.js

提交回复
热议问题