I know it\'s already discussed here, but there were no solution to get the whole document (including doctype).
$(document).html(); returns null
$(document).html();
null
You can do
new XMLSerializer().serializeToString(document);
for all browsers newer than IE 9