// do something else // do something How? ...">

JQuery check doctype

If doctype is <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> // do something else // do something 

How?

Thank.

+3
jquery doctype
Jun 15 '10 at 8:59
source share
5 answers

That's right, I came back after testing this in IE, Chrome, Firefox and Opera. IE will provide you with a complete doctype with the following code snippet:

 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 not true, as Chrome, Firefox, and Opera return null for nodeValue . Since none of them supports outerHTML , I can't think of a way to get the full doctype, but you can get the 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, this does not work in IE, but it would not be too difficult to parse them. You can use the if to verify that nodeValue not null , and return to checking systemId or publicId .

Script is used to run tests: http://jsfiddle.net/Cwb8q/

+3
Jun 15 '10 at 9:03
source share

You can use the jQuery.support object to test and work with certain browser functions (e.g. BoxModel).

+2
Jun 15 '10 at 9:03
source share

Try using the attribute "this.document.doctype" If it is not declared, the result will be zero, otherwise the result will be an object with doctype.

+1
Feb 27 '12 at 16:46
source share

document.doctype and document.firstChild both seem to return doctype, although I don't know how widely supported they are.

+1
Mar 28 '13 at 18:13
source share

You can try:

var doc = $ ("DOCTYPE");

-5
Jun 15 '10 at 9:04 on
source share



All Articles