解决 IE 6/7 中console对象兼容性问题

话不多说,直接上代码

(function (){
	        //创建空console对象,避免JS报错  
	        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',  
	                     'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];  
	        for(var i=0,l=funcs.length;i<l;i++) {  
	            var func = funcs[i];  
	            if(!console[func])  
	                console[func] = function(){};  
	        }  
	        if(!console.memory)  
	            console.memory = {};
 })();

复制这个自调函数到你的js中,这样IE6/7发烧友在访问页面的时候,就不会发现报错提示了。

前端技术群:263240563
原文地址:https://www.cnblogs.com/riven952465/p/5923760.html