Hi All,
Without getting into too much history on the why, I came into a situation where I needed to create a function to get various properties of !DOCTYPE so that other functions could adjust to work properly with certain DOCTYPEs (Strict, Transitional, etc.). I have tested the function in the following Windows browsers IE6+ FF3+ Chrome2+ and Safari3+ Opera9+. The only one that I can’t get working is Opera (testing with 9.64). I’m hoping that someone out that has a solution! Here is the code:
function getDOCTYPE(loc){
loc=locEval(loc)||self; // locEval is a function i use to qualify window/frame paths
var pid,sid,val,lng,ver,typ;
try{ // this is the node model that should be supported by all browsers. IE gets a hard error with it though.
pid=String(loc.document.doctype.publicId);
sid=String(loc.document.doctype.systemId);
}
catch(err){
val=String(loc.document.body.parentNode.parentNode.firstChild.nodeValue) // seems to only work in IE
//val=document.getElementsByTagName("!")[0].nodeValue // works in IE as well
pid=val.replace(/^[^\"]*\"([^\"]+)\".*/,"$1");
sid=((/http/).test(val))?val.replace(/^.*\"\s\"(http.*)/,"$1"):null
}
lng=((/xhtml/i).test(pid+sid))?"XHTML":"HTML";
typ=((/strict/i).test(pid+sid))?"Strict": ((/trans|loose/i).test(pid+sid))?"Transitional": ((/frame/i).test(pid+sid))?"Frameset": ((/basic/i).test(pid+sid))?"Basic": ((/mobile/i).test(pid+sid))?"Mobile": null;
ver=((/html\s*\d+\.?\d*/i).test(pid))?pid.replace(/^.*html\s*(\d+\.?\d*)\D*/i,"$1"):null;
return {publicId:pid,systemId:sid,language:lng,type:typ,version:ver,dtd:lng+" "+typ+" "+ver}
}
//...
alert(getDOCTYPE().dtd)
Any help would be greatly appreciated! :)