Created
December 20, 2010 10:44
-
-
Save antennaio/748243 to your computer and use it in GitHub Desktop.
Accessing Doctype with Javascript
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
var Doctype; | |
var publicId; | |
var search; | |
var htmlVersion; | |
if (document.doctype) { | |
publicId = document.doctype.publicId; | |
} else { | |
/* document.doctype doesn't exist - detect Explorer */ | |
var IE = /*@cc_on!@*/false; | |
if (IE) { | |
if (document.all[0].nodeType == 8) { | |
Doctype = document.all[0].nodeValue; | |
search = Doctype.match(/^DOCTYPE\s+(html|math|svg)\s+(SYSTEM|PUBLIC)\s+"(.*\/\/EN)".*$/i); | |
} | |
if (search[3]) publicId = search[3]; | |
} | |
} | |
if (publicId != null) { | |
if (publicId !== '') { | |
search = publicId.match(/^\-\/\/W3C\/\/DTD(.*)\/\/EN$/i); | |
htmlVersion = (search[1] != null) ? search[1] : 'Unknown'; | |
} else { | |
htmlVersion = 'HTML 5'; | |
} | |
} else { | |
htmlVersion = 'Unknown'; | |
} | |
alert (htmlVersion); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment