Skip to content

Instantly share code, notes, and snippets.

@Simounet
Created October 18, 2012 12:13
Show Gist options
  • Save Simounet/3911421 to your computer and use it in GitHub Desktop.
Save Simounet/3911421 to your computer and use it in GitHub Desktop.
JS Print_r
function print_r(obj) {
win_print_r = window.open('about:blank', 'win_print_r');
win_print_r.document.write('<html><body>');
r_print_r(obj, win_print_r);
win_print_r.document.write('</body></html>');
}
function r_print_r(theObj, win_print_r) {
if(theObj.constructor == Array || theObj.constructor == Object){
if (win_print_r == null)
win_print_r = window.open('about:blank', 'win_print_r');
}
for(var p in theObj){
if(theObj[p].constructor == Array|| theObj[p].constructor == Object){
win_print_r.document.write("<li>["+p+"] =>"+typeof(theObj)+"</li>");
win_print_r.document.write("<ul>")
r_print_r(theObj[p], win_print_r);
win_print_r.document.write("</ul>")
} else {
win_print_r.document.write("<li>["+p+"] =>"+theObj[p]+"</li>");
}
}
win_print_r.document.write("</ul>")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment