IE8 之浏览器模型和文档对象模型(browser mode & document mode)

 

IE8 RC1 developer tools 有这么两个按钮 即 Browser Mode(浏览器模式)和Document Mode(Dom模型)文档对象模型

 

Browser Mode: IE7,IE8,IE8 Compat View

Document Mode: Quirks,IE7 Standards,IE8 Standards

 

围绕这BM&DM各自的三种模式 IE8 RC1 能通过9种组合方式渲染网页 个人对这种混乱无比反感,窃以为这是对号称牺牲自身利益以通过Acid测试 向标准靠拢的IE8是一种讽刺。

 

如何兼容这9种组合模式?(貌似实际模式只有6 QuirksBrowser Mode基本无关)

 

Javascript 取得Document Mode

 

engine = null;

if (window.navigator.appName == "Microsoft Internet Explorer") {

    // 当前浏览器是IE,下面判断具体的显示模式

    if (document.documentMode) // IE8

        engine = document.documentMode;

    else // IE 5-7

    {

        engine = 5; //  quirks mode unless proven otherwise

alert("We can't support this mode or your IE is too old!");

window.location.href("http://www.microsoft.com/windows/products/winfamily/ie/default.mspx");

        if (document.compatMode) {

            if (document.compatMode == "CSS1Compat")

                engine = 7; // standards mode

        }

    }

    alert("IE的当前显示模式是" + engine);

}

 

而取得Browser Mode更简单了

 

<!--[if It 6]>

    <script  type="text/javascript">

        alert("Quirks")

    </script>

    <![endif]-->

 

    <!--[if IE 6]>

    <script  type="text/javascript">

        alert("IE6")

    </script>

<![endif]-->

 

    <!--[if IE 7]>

    <script  type="text/javascript">

        alert("IE7")

    if (document.documentMode == 8){

             document.createStyleSheet('Default/style/style.css');

         }

    </script>

    <![endif]-->

 

 

    <!--[if IE 8]>

    <script  type="text/javascript">

        alert("IE8")

    </script>

    <![endif]-->

 

通过组合 便能取得IE8 当前组合模式 适当加载CSS 或拒绝对过低版本提供支持