finding out if console is available

后端 未结 8 903
温柔的废话
温柔的废话 2020-12-23 20:00

I was wondering, how can i find out with javascript if the console object is available?

i have the problem that if i forget to remove a debug output

8条回答
  •  太阳男子
    2020-12-23 20:23

    try{
    console.log("test")
    }
    catch(e){
    console={},
    console.log=function(a){}
    }
    

    just put it at the top of your JS file and then use console.log(); without any worry for browser error, i also had this error in IE9

提交回复
热议问题