If doctype is <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
// do something
else
// do something
How to?
Thanks.
If doctype is <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
// do something
else
// do something
How to?
Thanks.
You could use the jQuery.support object to check for specific browser features (e.g. BoxModel) and working against them.
Right, I'm back after testing this in IE, Chrome, Firefox and Opera. IE will give you the full doctype with the following piece of code:
var doctype = document.documentElement.previousSibling.nodeValue;
// -> DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
Unfortunately, this is probably incorrect, as Chrome, Firefox and Opera return null
for nodeValue
. Since none of them support outerHTML
, I can't think of a way to get the full doctype, but you can get individual parts:
var doctype = document.documentElement.previousSibling;
console.log(doctype.systemId)
// -> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
console.log(doctype.publicId)
// -> -//W3C//DTD XHTML 1.0 Strict//EN
However, that doesn't work in IE, but it wouldn't be too difficult to parse those out. You can use an if
statement to check that nodeValue
is not null
and fall back to checking systemId
or publicId
.
Script used to run the tests: http://jsfiddle.net/Cwb8q/