Getting real source code using javascript?

OK I do not use js to know, but is there a way to get the real source code of the page with it?

document.body.innerHTML, for example, gives some kind of “fixed” version where invalid tags are removed.

I assume that using XMLHttpRequest on the source page might work, but it seems silly.

+4
source share
3 answers

This is because browsers parse the DOM and do not store HTML in memory. What is returned to you is the conversion of the browser of the current DOM back to HTML, which is the reason for the header tags and the absence of closing tags, where applicable.

XMLHttpRequest is best suited. In most cases, assuming the server does not send the header without a cache, and the HTML page has finished loading, XMLHttpRequest will be almost instantaneous because the file is being fetched from the cache.

+4
source

XMLHttpRequest is quite suitable for accessing JS of the same origin. You can access any JS document in a raw format using this technique if the browser does not interfere (i.e. Convert to DOM and vice versa).

I'm not sure I understand your comment re: XMLHttpRequest is stupid: is it because you are worried about possible duplication of work? those. get the code 2 times from the source server.

+3
source

I usually use FireBug when I want to read or copy source files.

+2
source