论坛首页 Web前端技术论坛

兼容console.log

浏览 1349 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2015-08-01  

在js前端开发时,为了调试经常会加上 console.log.但是在有的浏览器(比如IE)中会报错

怎么办呢?

在js文件最前面添加如下js代码:

if (window.console === undefined) {
    console = {
        log: function () {
        }, info: function () {
        }, debug: function () {
        }
    };
}

 

 

论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics