ignore firebug console when not installed

后端 未结 9 1380
旧时难觅i
旧时难觅i 2021-02-02 04:15

I use Firebug\'s console.log() for debugging my website. If I try viewing my website in browsers without Firebug then I get a console is not defined er

9条回答
  •  南旧
    南旧 (楼主)
    2021-02-02 04:33

    The linked solution is basically a variant(with a few extra functions) of this:

    EDIT The below code doesn't actually work when firefox is present. That'll teach for posting code without checking just to show off my not so 1337 operator || skillz:

    window.console = window.console || {};
    console.log = function(){};
    

    The reason for that is that firefox console is actually a getter only property off window. Hence we can't set it. Instead, something like this needs to be used:

    if (!window.console) {
      window.console = {};
      window.console.log = function(){};
    }
    

    Also, console.log (and console.warn, console.error) will work on Webkit browsers, including mobile Safari, pretty cool, huh?

提交回复
热议问题