Prevent error messages in the cases where a console object doesn't exist


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



Copy this code and paste it in your HTML
  1. // Prevent error messages in the cases where a console object doesn't exist
  2. if (!window.console || !console.firebug){
  3. var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml","group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
  4. window.console = {};
  5. for (var i = 0; i < names.length; ++i) {
  6. window.console[names[i]] = function() {};
  7. }
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.