Posted By

anagaiyahoocom on 06/26/11


Tagged

javascript


Versions (?)

Preventing javascript error using console.log on old browsers


 / Published in: JavaScript
 

This will detect if console.log is available in browser and display the message. Otherwise will display as alert message

  1. //Can use empty catch {} if don't want inadvertent alert message to be seen on production site
  2.  
  3. function trace(s) {
  4. try { console.log(s) } catch (e) { alert(s) }
  5. };
  6.  
  7.  
  8. //Can use empty catch {} if don't want inadvertent alert message to be seen on production site
  9.  
  10. function trace(s) {
  11. try { console.log(s) } catch (e) {}
  12. };

Report this snippet  

You need to login to post a comment.