Is there a way to acces the page HTML source code using javascript? I know that i can use the document.body.innerHTML but it contains only the code inside the body. I want to get all the page source code including head and body tags with their content, and, if it's possible, also the html tag and the doctype. Is it possible?
i don't know why in Firefox the document.documentElement object doesn't have the outerHTML property, but with the innerHTML i can get almost everything except the doctype so thank you!
mck89
2009-09-02 13:14:36
@mck89: no browser but IE will have `outerHTML`.
Crescent Fresh
2009-09-02 13:21:42
Be aware that the source you get with Firefox/most browsers is the "true" source you served up. In IE you will get the "live" HTML of the page including any changes the user has made to forms, any new DOM content etc. In IE it will also be the mixed case invalid tag soup that IE provides when requesting the .innerHTML of elements.
scunliffe
2009-09-02 13:35:12
+3
A:
One way to do this would be to re-request the page using XMLHttpRequest, then you'll get the entire page verbatim from the web server.
Paul Dixon
2009-09-02 13:08:31