Edit: Use XMLSerializer()
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 + '"' : '')
+ '>
' : '';
};
getDocTypeAsString() + document.documentElement.outerHTML
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…