Considering that HTML5 documents are declared in the block at the beginning with: <!DOCTYPE html>
, in addition there are the old versions as shown in this address:
link
If the HTML5 document does not usually get versioned, it means that if you see a systemId or a publicId declared in your block and that is different from: SYSTEM "about:legacy-compat"
. And that this document contains a type of doctype defined by <!DOCTYPE html>
or <!doctype html>
, we can do the following verification:
function checkHTML5() {
var isHtml5 = document.doctype.nodeName;
var systemId = document.doctype.systemId;
var publicId = document.publicId;
var xmlSerializer = new XMLSerializer();
var doctypeHTML = xmlSerializer.serializeToString(document.doctype);
var doctypeName = doctypeHTML.toLowerCase();
if (isHtml5 == "html" &&
(systemId == undefined ||
systemId.indexOf("about:legacy-compat")!==-1 ||
systemId == '') &&
publicId == undefined ||
publicId == '' &&
doctypeName.indexOf("!doctype") !== -1) {
return true;
}
console.log(publicId);
return false;
}
checkHTML5();