Riven952465

生活不止眼前的苟且,还有未来的苟且。

导航

解决 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发烧友在访问页面的时候,就不会发现报错提示了。

posted on 2016-09-30 14:47  Riven952465  阅读(336)  评论(0编辑  收藏  举报