Created
January 10, 2011 16:57
-
-
Save mckamey/773044 to your computer and use it in GitHub Desktop.
DocType extraction snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDocType(document) { | |
var node = document.firstChild; | |
while (node) { | |
var nodeType = node.nodeType; | |
if (nodeType === 10) { | |
// doctype | |
var doctype = '<!DOCTYPE '+(document.documentElement.tagName || 'html').toLowerCase(); | |
if (node.publicId) { | |
doctype += ' PUBLIC "' + node.publicId + '"'; | |
} | |
if (node.systemId) { | |
doctype += ' "' + node.systemId + '"'; | |
} | |
return doctype+'>'; | |
} | |
if (nodeType === 8 && (""+node.nodeValue).toLowerCase().indexOf("doctype") === 0) { | |
// IE represents DocType as comment | |
return '<!' + node.nodeValue + '>'; | |
} | |
node = node.nextSibling; | |
} | |
return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment