Debug console output
Say I make an XHR request and get back a HTML fragment (or the whole page), how can I see the unformatted output of that in the console, tags and all.
At the moment it displays formatted output and I need to take a look at what an HTML doc looks like at the device end. Whats a good work around for this?
TIA
Dave
3 Answers
-
From a stackoverflow post
function h(s) { return s.split('&').join('&').split('<').join('<').split('"').join('"'); }
-
I guess you could try a JavaScript equivalent to the PHP function htmlspecialchars
http://phpjs.org/functions/htmlspecialchars:426
In fact this whole site in extremely useful for people who know PHP and need a JavaScript equivalent ;)
http://phpjs.org/
-
Probably the easiest way would be to make a function that might look something like this, and pass the results from your the call into it:
function dehtml( html ){ var text = html.replace( /&/g, "&" ); text = text.replace( /</g, "<" ); text = text.replace( />/g, ">" ); return text; }
If its used in a lot of places, you might even have this function also call the logging function.