The browser reports that the console object cannot be found, so we manually construct a console object with the same interface and place it in the window. Empty methods and empty objects are used here. In this way, even in very old browsers, the code containing console.xxxxx will still not report errors and run perfectly.
Attached below is the repair compatibility code, which must be placed before the first console.xxxx call, otherwise it will be meaningless.
(function (){
/ /Create an empty console object to avoid JS errors
if(!window.console)
window.console = {};
var console = window.console;
var funcs = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml',
'error', 'exception', 'group', 'groupCollapsed', 'groupEnd',
'info', 'log', 'markTimeline', 'profile', 'profileEnd',
'info', 'log', 'markTimeline', 'profile', 'profileEnd',
'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];
for(var i=0,l=funcs.length;i var func = funcs[i];
if(!console[func])
console[ func] = function(){};
}
if(!console.memory)
console.memory = {};
})();