Preventing javascript error using console.log on old browsers


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.