PDA

View Full Version : View Source bookmarklet


beetle
08-20-2002, 11:43 PM
Here's a bookmarklet I made for viewing page source. Lets you see how the browser sees the HTML. Tested on IE6javascript:var h = document.documentElement.outerHTML; var nTitle = window.location.href; h=h.replace(/</g, '&lt;'); var srcWin; srcWin = window.open('','srcWin',''); with (srcWin.document) { writeln('<html><head><title>Source Code for '+nTitle+'</title></head><body>'); writeln('<pre>'); writeln(h); writeln('</pre>'); writeln('</body></html>'); close(); }

jkd
08-21-2002, 12:03 AM
This works in Mozilla:

javascript:window.open('about:blank').document.write('<pre>' + unescape((new XMLSerializer()).serializeToString(document).replace(/</g, '&lt;')) + '</pre>')

And this is a shorter version for IE:

javascript:window.open('about:blank').document.write('<pre>' + document.documentElement.outerHTML.replace(/</g, '&lt;') + '</pre>')

beetle
08-21-2002, 12:11 AM
Cool. I know someone could make it shorter...course that version doesn't include the TITLE...:p