JavaScript: code snippet

note for self: a piece of code to enable me to write ‘console.log’ and not have IE get unhappy :/

// this creates the console object if it’s not present – most useful for IE7,8,9
if (! (“console” in window) || !(“firebug” in console)) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group" , "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
window.console = {};
for (var i = 0; i <names.length; ++i) window.console[names[i]] = function() {};
}

This entry was posted in html, javascript, user tools. Bookmark the permalink.