How do I get the entire page's HTML with jQuery?
You could try:
$("html").html();
If you want to also capture the html tags you could concatenate them to the html like this:
function getPageHTML() {
return "<html>" + $("html").html() + "</html>";
}
Don't forget the <html>
tag can have attributes too. If you want the whole document this should work.
$('html')[0].outerHTML
It's also trivial without jQuery.
document.documentElement.outerHTML
If you also want to include the doctype, it's a little more involved.
var getDocTypeAsString = function () {
var node = document.doctype;
return node ? "<!DOCTYPE "
+ node.name
+ (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '')
+ (!node.publicId && node.systemId ? ' SYSTEM' : '')
+ (node.systemId ? ' "' + node.systemId + '"' : '')
+ '>\n' : '';
};
getDocTypeAsString() + document.documentElement.outerHTML
Use:
document.body.innerHTML