Skip to content

Instantly share code, notes, and snippets.

@serbanghita
Created July 2, 2013 11:04
Show Gist options
  • Save serbanghita/5908443 to your computer and use it in GitHub Desktop.
Save serbanghita/5908443 to your computer and use it in GitHub Desktop.
Cross Browser console.log implementation. I use this to be able to call log(arg1, arg2, ..., argN) in every browser.
// Cross-browser support for meaningful console.log
// @usage: log(arg1, arg2, ..., argN)
var log = function(){
if( console && console.log ) {
switch( typeof console.log ){
// Browser supports the function.
case 'function':
console.log.apply(console, arguments);
break;
// IE7 and IE8 partially support, they expose an object
// that cannot handle .apply() or .call()
case 'object':
var msg = [];
for( var i in arguments ){
msg.push( arguments[i] );
}
console.log( msg.join(" ") );
break;
}
} else {
// For everything else there are some hidden divs.
var elem = doc.createElement('pre');
elem.className = 'consoleDebug';
elem.style.cssText = 'display:none;';
for( var i in arguments ){
elem.innerHTML += arguments[i] + "\n";
}
doc.body.appendChild( elem );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment