Skip to content

Instantly share code, notes, and snippets.

@arrix
Created October 26, 2010 06:40
Show Gist options
  • Save arrix/646435 to your computer and use it in GitHub Desktop.
Save arrix/646435 to your computer and use it in GitHub Desktop.
function getHTMLSource() {
var doc = document;
var dt = document.doctype;
var dtSource = "";
if (dt) {
dtSource = '<!DOCTYPE html PUBLIC';
if (dt.publicId) dtSource += (' "' + dt.publicId + '"');
if (dt.systemId) dtSource += (' "' + dt.systemId + '"');
dtSource += '>';
}
var docSource;
var de = doc.documentElement;
if (de.outerHTML){
docSource = de.outerHTML;
} else if (XMLSerializer) {
docSource = new XMLSerializer().serializeToString(de);
} else{
docSource = '<html>' + document.innerHTML + '</html>';
}
return dtSource + docSource;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment