JavaScript console debug
Quick JavaScript snippet for logging to the console if available.
If it's not available (mobile browsers, IE, FF without firebug) it won't break the rest of the code.
Also comes with a global debug on/off
var debug = true;
function log(str) {
if (debug) {
var currentTime, h, m, s;
currentTime = new Date;
h = currentTime.getHours();
m = currentTime.getMinutes();
s = currentTime.getSeconds();
try {
console.log("[" + h + ":" + m + ":" + s + "]\t" + str);
} catch (e) {}
}
}
Written by Jason M
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Console
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#