Created
August 24, 2012 23:06
-
-
Save tomgrohl/3456919 to your computer and use it in GitHub Desktop.
A simple function for getting if a document is XHTML+XML
This file contains 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 getContentType() { | |
var type = "text/html", | |
rXHTML_XML = /application\/xhtml\+xml/i, | |
element = $(document).find("meta[content][http-equiv='Content-Type']"); | |
if( element.length ) { | |
content = element.attr("content"); | |
if( rXHTML_XML.test( content ) ) { | |
type = "application/xhtml+xml"; | |
} | |
} | |
return type; | |
} | |
function isXHTML() { | |
var node = document.doctype, | |
contentType = getContentType(), | |
rDOC = /TR\/xhtml(1|11)\/DTD\/xhtml(1|11)/i, | |
type = node.systemId; | |
if( contentType === "application/xhtml+xml" || ( type && contentType === "text/html" && rDOC.test( type ) ) ) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment