Install doctype using javascript

I have an html page without a doctype declaration declared to the server (say A). This is a selection of js files from another server (say B). js creates the necessary html page to display. IE8 is now causing problems because doctype is not declared (sets itself to IE5 quirks mode)

Now doctype is the first line, and it cannot be done this way (using js to install doctype). Is it possible to set the meta tag to set the page mode to standard mode? Or is there any other, I can set the page to a standard page without changing the html page from server A.

+4
source share
1 answer
var nodeDoctype = document.implementation.createDocumentType(
 'html',
 '-//W3C//DTD XHTML 1.0 Transitional//EN',
 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdd'
);
if(document.doctype) {
    document.replaceChild(nodeDoctype, document.doctype);
} else {
    document.insertBefore(nodeDoctype, document.childNodes[0]);
}

:

doctype JS, ( : http://www.webmasterworld.com/forum91/4856.htm), . . doctype js, :

window.location = window.location+"?doctype=newdoctype"

, , .

+3

Source: https://habr.com/ru/post/1525019/


All Articles