问题
My webpage has the following doctype
<!DOCTYPE html>
The above line is the very first line on my HTML page.
These are no extra spaces or comments before this line.
Still the page goes in IE7 document mode and <!DOCTYPE html>
gets commented out when i check the html page using developer tools.
I know that I can force a certain document mode by including the following meta tag
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
But I am not supposed to use this, niether I am supposed to go to tools and change the compatibility view settings (Tools -> Compatibility view settings).I have also checked whether the document is valid HTML5 document using a HTML5 validator.
Some solutions I searched were of CSS causing this problem ie. beacuse of using Type 1 font (Helevetica). I checked my css and nowhere we are using this font.
Basically I need to know what are the reasons that is causing this unusual behaviour. Is it some css or javascript that is causing this.
EDIT : as mentioned in one of the comments I tried loading a simple html page as follows
<!DOCTYPE html>
<html>
<head>
<title>Hello Wrold</title>
</head>
<body>
<div>hello world!!</div>
</body>
</html>
It is behaving the same way. Page loads in IE7 document mode.
回答1:
Check your html file and make sure there is no BOM (Byte Order Mark) at the beginning of the document. This can cause problems in some browsers. In order to check, use something like Adobe Dreamweaver or Notepad++. Open file in ANSI mode in notepad and check if there are characters before, delete them and save as UTF-8 without bom (option when saving in notepad++)
回答2:
My experience is that this is just the way IE DevTools works when it emulates different document modes. It doesn't depend on the content of your page.
来源:https://stackoverflow.com/questions/16785222/ie9-throws-my-page-in-ie7-document-mode-and-doctype-html-gets-commented-out