Skip to content

Instantly share code, notes, and snippets.

@robert-wallis
Created September 17, 2011 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robert-wallis/1223704 to your computer and use it in GitHub Desktop.
Save robert-wallis/1223704 to your computer and use it in GitHub Desktop.
Display the contents of a JavaScript object in the #debug id on the page. Or alert it if there was no debug.
// debug() - Copyright (C) 2006-2008 Robert Wallis
function debug(obj, name)
{
var t = "";
if (name) {
t += ""+name+":";
}
for (var i in obj) {
t += i+"=\""+obj[i]+"\"\n";
}
var d = document.getElementById('debug');
if (d) {
d.innerHTML += '<textarea style="font-family: monospace; padding: 8px; background-color:#525252; color:#FF9900;" cols=80 rows=30>'+t+'</textarea>';
} else {
alert(t);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment