Whereas HTML5 documents are declared in the block early with: <!DOCTYPE html>
, in addition to them there are the old versions as demonstrated at this address:
https://www.totalvalidator.com/support/doctypes.html
If as a rule the HTML5 document does not receive versioning, it means that a systemId or a publicId declared in its 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 make the following check:
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();
All right, it worked perfectly.
– KaduAmaral