程序员在开发代码的过程中,使用console作为调试代码过程的一种手段。
发布到测试生产环境,发现IE8 出现加载错误。使用开发者工具调试,发现可以绕过问题。
通过网络搜索和在项目中进行修正。
以下办法均可生效:
1、去除console代码(由于是调试代码,不影响线上使用)。
2、在基础Js脚本文件中加入:
1 (function() {
2 var method;
3 var noop = function () {};
4 var methods = [
5 'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
6 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
7 'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
8 'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
9 ];
10 var length = methods.length;
11 var console = (window.console = window.console || {});
12
13 while (length--) {
14 method = methods[length];
15
16 // Only stub undefined methods.
17 if (!console[method]) {
18 console[method] = noop;
19 }
20 }
21 }());
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLiYWan5CNxITNxAjMwIzLcV3b05WYtlWYi9CXz52bjlGdv1WRvwVbvNmLzd2bsJmbj5yd3d3Lc9CX6MHc0RHaiojIsJye.gif)
喜欢技术、热爱生活。