finding out if console is available

后端 未结 8 888
温柔的废话
温柔的废话 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:27

    Simplest way would be:

    if (window.console){
       console.log('do something');
    }
    

    instead of just writing:

    console.log('do something');
    
    0 讨论(0)
  • 2020-12-23 20:30

    Check the property exists as a member of window:

    if (window.console) {
    }
    

    next to that problem i am interested in all informations about the console object. has anybody some documentation link, or so? is it a standard? and so on...

    Check out the Firebug documentation for the Console API; Chrome and Safari implement most, but not all, of the methods listed there. There's no standard defining what should be in the console, so you'll need to test each browser to see if it supports the feature.

    0 讨论(0)
提交回复
热议问题