get doc dec info
Anyone know a simple way to get doctype declaration/definition info useing javascript. Only needs to work in IE
e.g.
This sort of thing:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
Cheers
e.g.
This sort of thing:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
Cheers
OK how does that work. The second I give up and ask a forum, I find the goodies I need. I've not tested, but this certainly looks like the trick:
| Code: |
| /******************************
Version info "object" ******************************/ function versionInfo() { this.xhtml=""; this.version=""; this.importance=""; } function detectDoctype(){ var re=/\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi; var myversionInfo=new versionInfo(); /********************************************* Just check for internet explorer. **********************************************/ if(typeof document.namespaces != "undefined"){ if(document.all[0].nodeType==8) re.exec(document.all[0].nodeValue); else return null; }else{ if(document.doctype != null) re.exec(document.doctype.publicId); else return null; } myversionInfo.xhtml=RegExp.$1; myversionInfo.version=RegExp.$2; myversionInfo.importance=RegExp.$3; return myversionInfo; } var myversionInfo=detectDoctype(); if(myversionInfo != null){ alert(myversionInfo.xhtml); alert(myversionInfo.version); alert(myversionInfo.importance); } else{ alert("There is no DOCTYPE in the code!"); } |
| Phil Teare wrote: |
| OK how does that work. The second I give up and ask a forum, I find the goodies I need. |
That would be Murphy's Law of Google.
Why do you need to sniff the doctype with JS? If you want the rendering mode you can use document.compatMode.
Simon Pieters
Simon Pieters


