IE11新文档模式Edge介绍与评估,及在WebBrowser应用中的使用。

浏览器模式与文档模式概念是怎么来的?

1.浏览器模式与文档模式概念起源

为了解决兼容性的问题,在IE浏览器(IE8, IE9, IE10)中,引入了浏览器模式和文档模式两个概念,浏览网页时可以通过按F12键看到这两种模式。

2.浏览器模式的主要作用是为兼容较早版本的IE,它会控制浏览器发出的UserAgent,表示以哪个版本的浏览器发出请求,以此来允许为某个特定IE版本设计的代码正确执行(举例来说:有些代码真是判断ie版本的,还有css里也有判断ie版本的)。

3.文档模式的主要作用是影响浏览器显示网页HTML的方式,在接到返回的HTML文件后,决定以哪个IE版本的文档模式解析该页面(举例来说:JS脚本就是依赖文档模式,IE9的JS变化就需要IE9文档模式来支持)。

 

怎么设置文档模式

•1.使用 X-UA-Compatible 标头可指定页面支持的 IE 版本。

•2.使用 document.documentMode 可确定网页的文档模式。
•3.代码示例:
    <html>
        <head>
            <title>abc</title>
            <META http-equiv="X-UA-Compatible" content="IE=9" > </META>
            <script type="text/javascript">
                function abc() { alert(document.documentMode); }  
            </script>          
        </head>
        <body onload="abc()"></body>
    </html>

 

IE11 Document mode changes

•Windows Internet Explorer 8 introduced document modes to help you transition from features supported by earlier versions of the browser to those specified by modern standards and other browsers. Subsequent releases of Windows Internet Explorer continued this transition by introducing new document modes that emulated features supported by earlier versions while introducing support for features defined by industry standards.
•While many web sites were updated to provide richer experiences to other browsers, some continued to use the presence of legacy feature support to provide legacy experiences to Internet Explorer, even though recent versions of the browser supported the experiences presented to other browsers.
•Starting with IE11, edge mode is the preferred document mode; it represents the highest support for modern standards available to the browser.
•Use the HTML5 document type declaration to enable edge mode: <!doctype html>
•Edge mode was introduced in Internet Explorer 8 and has been available in each subsequent release. Note that the features supported by edge mode are limited to those supported by the specific version of the browser rendering the content.
•Starting with IE11, document modes are deprecated and should no longer be used, except on a temporary basis. Make sure to update sites that rely on legacy features and document modes to reflect modern standards.
•If you must target a specific document mode so that your site functions while you rework it to support modern standards and features, be aware that you're using a transitional feature, one that may not be available in future versions.
•If you currently use the x-ua-compatible header to target a legacy document mode, it's possible your site won't reflect the best experience available with IE11.

 

文档模式以及与IE11 的兼容性

•IE 11 中的兼容性改进可让较早版本的网站以最新的标准模式运行,默认情况下,不需要模拟以前的浏览器行为。由于较早版本的网站现在能够正常运行,因此我们已决定 IE 10 文档模式将是最后一个新文档模式。而开发人员需要转变为使用 IE 11 中的 Edge 模式。也就是说,IE已经完成了标准化过渡,因此老模式就退出历史舞台了,从IE11到以后的IE12, IE13…,边缘模式成为首选文档模式,都要用Edge了。它代表可供浏览器使用的现行标准的最高支持。

•如果决定仍然需要仿真某个以前的浏览器环境 IE 10 或更早版本,则可以更改服务器配置,将 X-UA-Compatible 元标记添加到 HTTP 标头。更改此内容值可让您的网站按所选的 IE 版本进行显示。例如,如果希望内容像在 IE 10 中显示的那样,可在 X-UA-Compatible 元数据中指定值 IE=10。
 

X-UA-Compatible支持的值

 

内容值  

含义  

IE=5

使用   Internet   Explorer 5 Quirks 模式呈现内容。

IE=7

使用   Internet   Explorer 7 标准模式呈现内容。

IE=8

使用   Internet   Explorer 8 标准模式呈现内容。

IE=9

使用   Internet Explorer 9   标准模式呈现内容。

IE=10

使用   Internet   Explorer 10 标准模式呈现内容。

IE=Edge

使用最新模式呈现内容。建议所有网站都采用此模式。

 

注意:不要指定未来的内容值,如 IE=11 和更高版本。而应使用 IE=Edge 来获取最新模式。也就是说,IE11时,我们要这样用:

<META http-equiv="X-UA-Compatible" content="IE=Edge" > </META>

 

示例总结

•<!doctype html>是用来启用Edge模式的一个方法,但是<!doctype html>这种方法,在WebBrowser应用中不起作用,还是被认为是Quirks模式 。

•X-UA-Compatible也是用来启用Edge模式的一个方法,X-UA-Compatible这种方法,在浏览器及WebBrowser中都起作用,都有效。

•虽然写IE=11也有同样的效果,鉴于微软不再建议这样写,所以我们应用标准的方法:<META http-equiv="X-UA-Compatible" content="IE=Edge" > </META>
 
本机IE11下使用WebBrower应用时的建议做法
•不使用企业模式,它在BancsLink这种WebBrowser应用中不可用,它在不使用网站而是直接打开磁盘上HTM页面浏览时也不起作用。具体见上一帖:IE11企业模式介绍及可用性评估
•对于不使用IE11标准功能的HTM页面,只要保持旧版本不做任何修改,文档模式就会被认为是老版本的Quirks模式(版本号等于5,实际兼容IE5.5及IE6等),也就是说,不改就是用旧版本。
•对于要使用IE11标准功能HTM页面,使用设置X-UA-Compatible的方式,但不要再指定版本号,如 IE=11 和更高版本,而使用 IE=Edge 来获取最新模式。也就是要这样用:
<META http-equiv="X-UA-Compatible" content="IE=Edge" > </META>
 
PDF下载:pdf
 
posted on 2015-01-23 15:04  BobLiu  阅读(9150)  评论(1编辑  收藏  举报