Which browsers support console.log()?

后端 未结 8 1513
生来不讨喜
生来不讨喜 2020-12-03 13:12

Do all browsers support this? I would like to output an error using console.log() but was wondering if this supported by all browsers?

console.         


        
8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 14:14

    Although not all browsers support that, it can be accomplished with a small chunk of code.

    In his book, "Secrets of Javascript Ninja", John Resig (creator of jQuery) has a really simple code which will handle cross-browser console.logissues. He explains that he would like to have a log message which works with all browsers and here is how he coded it:

     function log() {
      try {
         console.log.apply(console, arguments);
      } catch(e) {
      try {
         opera.postError.apply(opera, arguments);
      }
      catch(e) {
         alert(Array.prototype.join.call( arguments, " "));
      }
    }
    

提交回复
热议问题