Override intranet compatibility mode IE8

后端 未结 19 2055
执念已碎
执念已碎 2020-11-22 10:04

By default IE8 forces intranet websites into compatibility mode. I tried changing the meta header to IE8, but it doesn\'t acknowledge the meta header and just uses the brows

相关标签:
19条回答
  • Michael Irigoyen is correct BUT it is a little more complicated...

    if you are using the wonderful boilerplate by Paul Irish then you will have something like the following:-

    <!doctype html>
    <!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
    <!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]-->
    <!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]-->
    <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
    <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    

    This will NOT work as expected and force in IE into compatibility mode in an Intranet environment if you have the "Display intranet sites in compatibility view" checked. You need to remove the conditional IE comments to prevent Intranet compatibility mode.

    So the following code will work:

    <!doctype html>
    <html class="no-js" lang="en">
    <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    

    Basically if you trigger conditional IE comments before the <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> statement then you will be forced into compatibility mode in an Intranet environment if you are running IE9 with the default settings.

    UPDATE — ADDITIONAL INFO: But note that there is a trick that will make the HTML5 boilplate work:

    Add an emtpy, conditional comment before the DOCTYPE. And note as well, that when you do that, then you can also add conditional comments around the X-UA-Compatible directive, making the page HTML5-valid as well. So for instance:

    <!--[if HTML5]><![endif]-->
    <!doctype html>
    <!--[if the boilerplate conditionals goes here<![endif]-->
    <head>
    <!--[if !HTML5]>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <![endif]-->
    

    A blog post that was inspired by the first part of this answer, has more detail. And by the way: As mentioned in that blog post, one can also replace the conditional comment before the DOCTYPE with a semi conditional comment with no condition: <!--[]-->. Thus, like so:

    <!--[]-->
    <!doctype html>
    <!--[if the boilerplate conditionals goes here<![endif]-->
    <head>
    <!--[if !HTML5]>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <![endif]-->
    

    But note that the latter variant (<--[]--><!DOCTYPE html>) will, as explained e.g by this answer to another question, activate the well know problem that it — for legacy IE versions without support for the X-UA-Compatioble (read: for IE7 and IE6) — bring the browser into into quirks-mode.

    0 讨论(0)
提交回复
热议问题