The HTML5 doctype is not triggering standards mode in IE8

前端 未结 3 1772
青春惊慌失措
青春惊慌失措 2020-12-09 22:20

i work for a company where all our sites currently use the XHTML 1.0 transitional doctype (yes i know it is very old school). I want to change them all to use the HTML5 doct

相关标签:
3条回答
  • 2020-12-09 22:51

    I'm not sure if this helps, but in IE9, you must use:

    <!DOCTYPE html>
    

    and the following meta tag:

    <meta http-equiv="X-UA-Compatible" content="IE=9">
    

    After testing combinations of these two, here's what I found:

    • No Doctype or Meta Tag:
      Quirks Mode, IE Engine = 5

    • Doctype Only:
      Standards Mode, IE Engine = 7

    • Doctype and Meta Tag
      Standards Mode, IE Engine = 9

    • Meta Tag Only
      Standards Mode, IE Engine = 9

    How to detemine mode type and engine:

    • document.compatMode: CSS1Compat = standards mode, otherwise you're in quirks mode

    • document.documentMode: returns which engine IE is using to render the document


    Notes:

    • Usually Doctype must be the first line in your file. I'm not sure, but I think an XML tag can precede it. If anything else precedes it your likely to break your doctype declaration:
    • Meta Tag must be placed in <HEAD>
    • Your post is 25 days old, so I assume you have a solution. Even so, I'm not sure if these IE9 settings are appropriate for your problem. You'll have to examine window.document.compatMode and window.document.documentMode to determine if they are viable under IE8
    • Change meta tag to <meta http-equiv="X-UA-Compatible" content="IE=8">
    • Altough it is possible to use the meta tag only, I wouldn't recommend using it without a doctype. As this might cause problems with XML, CSS, and Script

    I spent hours trying to figure this out and posting this article so I hope someone actually gets some use out of my research. May the source be with you...

    0 讨论(0)
  • 2020-12-09 23:02

    Both the XHTML 1.0 Transitional doctype (when used by the spec, with a URL) and <!doctype html> trigger “Standards Mode” in IE. If this does not happen, there is a multitude of reasons that probably have nothing to do with the doctype change (and can only be analyzed if additional information, such as a URL, is available); see IE 8 and IE 9 complications in Activating Browser Modes with Doctype.

    Changing to <!doctype html> is pointless and a potential problem, unless you not actually changing the markup. In validation, which is the other reason for using doctype, it causes a completely different analysis and quite often error messages about constructs that are valid in XHTML 1.0.

    0 讨论(0)
  • 2020-12-09 23:09

    There’s a couple of settings in IE 8 that can cause pages to render in Compatibility Mode, regardless of the page’s HTML content or HTTP headers:

    1. Page > Compatibility View Settings

      • If “Display intranet sites in Compatibility View” is checked, then IE will render all sites on the local network in compatibility view. (This has happened to me a few times during development.)

      • If “Include updated website lists from Microsoft” is checked, then IE will download a list of websites from Microsoft and render them all in compatibility view.

      • If “Display all websites in Compatibility View” is checked, then, well, you can guess what happens.

    2. Tools > Internet Options > Advanced > Browsing

      • If “Automatically recover from page layout errors with Compatibility View” is checked, then IE will sometimes switch to compatibility view if it thinks a page’s layout is broken.

    3. And, finally, if you navigate to a page and then click on Page > Compatibility View (or click on the compatibility view icon in the address bar), then that page will be rendered in compatibility view.

    So, although it’s worth putting X-UA-Compatible in there and using a doctype like the HTML5 one (so that your intentions are clear), always check these settings first when testing.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题