IE8适配主视图(IE7 mode)与单独IE7的差别详解

2021-03-21 20:38 jianzhan

1. IE8适配主视图简述
以便处理新版访问器兼容问题旧网站的难题,IE8访问器提升了1种叫做“适配性主视图”的作用,可让网页页面以IE7的编码标准来显示信息,这样,就可以够很好的处理绝大多数(但并不是所有)因为编码规范不1致引发的网页页面难题。
2.“访问器方式”和“文本文档方式”之间的差别
适配性主视图涉及到两个关键的作用就是“访问器方式browser mode”和“文本文档方式document mode”,在IE8中按F12键,开启“开发设计人职工具”,在工具栏中能够看到“访问器方式”和“文本文档方式”的切换菜单,在其中能够挑选切换到IE7/8等不一样的网页页面方式。
那“访问器方式”和“文本文档方式”之间有甚么差别呢?
“访问器方式”用于切换IE对于该网页页面的默认设置文本文档方式、对不一样版本号访问器的标准备注释析、推送给网站服务器的客户代理商(User-Agent)标识符串的值。网站能够依据访问器回到的不一样客户代理商标识符串分辨访问器的版本号和安裝的作用,这样便可以向不一样的访问器回到不一样的网页页面內容。
默认设置状况下,IE8的访问器方式为IE8。客户能够根据点击详细地址栏周围的适配性主视图按钮来手动式切换到不一样的访问器方式。在IE8中,IE8适配性主视图会以IE7文本文档方式来显示信息网页页面,另外会向服务器推送IE7的客户代理商标识符串。
“文本文档方式”用于特定IE的网页页面排版模块(Trident)以哪一个版本号的方法来分析并3D渲染网页页面编码。切换文本文档方式会致使网页页面被更新,但不容易变更客户代理商标识符串中的版本号号,也不容易从服务赏识新免费下载网页页面。切换访问器方式的另外,访问器也会全自动切换到相应的文本文档方式。
1般来讲,二者都要设定为一样的版本号,可是,假如不一样又怎样呢?或说二者是不是有优先选择级差别呢?
请看下面的msdn帖子:Just The Facts: Recap of Compatibility View
http://blogs.msdn.com/b/ie/archive/2009/02/16/just-the-facts-recap-of-compatibility-view.aspx
精粹摘抄:
•We’ve evangelized use of the X-UA-Compatible tag to websites unable to update to support IE8’s Standards mode. The tag allows a web author to declare the exact standards mode behavior for which their website works best – IE8 Standards (again, the default when no header is present) or IE7 Standards. For example, using the value ‘IE=EmulateIE7’ causes IE8 to display a website “as IE7 would have”.
•We’ve provided end-user and corporate / IT mitigations to the website compatibility problem under the umbrella term ‘Compatibility View’. ‘Compatibility View’ allows IE8 users to have a great experience even when visiting websites that haven’t yet performed either of the above two steps. It also helps IT organizations preserve compatibility with the large number of line-of-business websites that are Internet Explorer 7 capable today.
•Compatibility View and the X-UA-Compatible tag are not equivalent. Compatibility View is something you do on the client. It affects three things: the User Agent string, the Version Vector (used in evaluation of conditional comments), and what mode DOCTYPEs that trigger Standards map to – IE8 Standards or IE7 Standards. The X-UA-Compatible <META> tag / header is something you use in page content / server-side and, when present, completely overrides Compatibility View settings on the client. It affects two things: the Version Vector and what mode DOCTYPEs that trigger Standards map to. It can’t affect the UA string as it’s already too late to change that – the client’s already made the GET request to the server (and it contains a UA string). What this means to developers is that if your site pivots on the User Agent string, adding just the X-UA-Compatible tag (to cause IE8 to display your site in IE7 Standards mode) won’t make your website compatible – you’ll also need to update your User Agent string detection logic as well.
总结,有两种方法可使IE8适配IE7方式,1是在服务器端,根据程序流程员操纵改动网页页面的文本文档方式document mode,也便是根据Meta(X-UA-Compatible IE=EmulateIE7), 强制性使网页页面变成适配IE7的网页页面。
以下:

拷贝编码
编码以下:

<head runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>cest</title>
</head>

假如不写这句,就会默认设置应用IE8了。
另外一个便是在顾客端,当网站还没来得及改动Meta时,客户假如装了IE8,发现没法一切正常显示信息,这时候最终1招便是点一下Compatibility View按钮了,它最后反映在User Agent上,也便是说点了适配性主视图按钮,再递交的Http恳求头就被改变为 MSIE7.0,使顾客端掩藏成IE7来推送恳求。
以下:
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
依照该MSDN的说法,改动Meta(X-UA-Compatible IE=EmulateIE7)的优先选择级要高于点一下Compatibility View,它能够遮盖掉Compatibility View的挑选, 也便是说,1旦网站改版进行公布后,要是设定了Meta , 便可以使原先客户访问器上设定的Compatibility View作废,从而全自动融入新版本号的IE8访问器。
3.IE8适配主视图(IE7 mode)与单独IE7不彻底同样
请看Technet.Microsoft的帖子:
What Is Compatibility View?
http://technet.microsoft.com/zh-cn/ff966533
Compatibility View is a feature of Windows Internet Explorer 8 that enables the browser to render a webpage nearly identically to the way that Windows Internet Explorer 7 would render it.
In Internet Explorer 8, Compatibility View changes how the browser interprets code that is written in CSS, HTML, and the Document Object Model (DOM) to try to match Internet Explorer 7. A site that a user views in Internet Explorer 8 Compatibility View is almost identical to a site that the user views in Internet Explorer 7. However, Compatibility View does not change how the browser interprets all code. For example, the changes in Internet Explorer 8 for how the browser handles ActiveX, the parser, AJAX, JavaScript, networking, and security might still cause compatibility issues. Compatibility View does not change these behaviors.
In an enterprise environment, some areas have lower risk for compatibility issues. For example, Intranet Zone websites use Compatibility View by default. Client web applications that render by using the Web Browser Control, or the WebOC (Internet Explorer rendering engine), also have a low risk for compatibility issues because Internet Explorer 8 defaults to a compatibility mode for the WebOC. However, the default configuration settings for Compatibility View might not ensure complete compatibility. To determine if a website or web application is compatible with Internet Explorer 8, you should test the website or web application.
For more information about the differences between Internet Explorer 8 Compatibility View and Internet Explorer 7, see the Site Compatibility and Internet Explorer 8 blog. For a list of what to check when you upgrade to Internet Explorer 8, see the Internet Explorer 8 Readiness Toolkit.
For more information about Compatibility View, see the Internet Explorer Team Blog.
请看MSDN的帖子:
1. Differences between IE8 Compatibility View and IE7
http://blogs.msdn.com/b/ie/archive/2009/03/12/site-compatibility-and-ie8.aspx
摘抄:
We strive to make Compatibility View behave as much like IE7 as possible, but we do make exceptions. Many of these exceptions enable improved security and accessibility features immediately, even for sites that have not yet migrated to IE8 Standards Mode.
2. What EXACTLY does Compatibility View do in IE8?
http://webmasters.stackexchange.com/questions/2219/what-exactly-does-compatibility-view-do-in-ie8
精粹摘抄:
Compatibility View renders the page as if it was Internet Explorer 7 (including Javascript). There are a few differences between IE8 with CV and pure IE7 but essentially it is the same. If you really want the detail of what is going on then read Just The Facts: Recap of Compatibility View from the IE MSDN blog.
You can also force IE8 to use CV with this meta tag:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
If you are having problems, I'd suggest first checking you have a legitimate doctype in your HTML (the simplest one is <!DOCTYPE html> which forces standards mode). That will solve 90% of your problems, especially with IE6.
结果是:IE8适配方式与单独的IE7是不一样的,還是一些差别的,它其实不是在IE8里简易包括了1个详细的IE7。
4.实际差别的细节
1. Cross Document Communication
Hacks enabling cross-domain, cross-document communication have been disabled for security reasons.
处理计划方案:Use Cross Document Messaging (XDM) to work around this change.
2. Extending the Event Object
IE exposes new properties for certain AJAX features such as Cross Document Messaging (XDM), even in Compatibility View. Adding custom properties to the Event object can conflict with these new properties, such as "source".
event.source = myObject; // Read-only in IE8
处理计划方案: Change the names of conflicting custom properties to avoid collision.
event.mySource = myObject;
3. Attribute Ordering
The ordering of attributes has changed, affecting the attributes collection as well as the values of innerHTML and outerHTML. Pages depending on a specific attribute ordering may break.
attr = elm.attributes[1]; // May differ in IE8
处理计划方案: Reference attributes by name as opposed to their position within the attributes collection.
attr = elm.attributes["id"];
4. Setting Unsupported CSS Values
Assigning CSS values that were unsupported in IE7 but are supported in IE8 Standards Mode will not generate exceptions in IE8 Compatibility View. Some sites use these exceptions to determine if a particular value for a CSS property is supported or not.

拷贝编码
编码以下:

Try
{
elm.style.display = "table-cell";
} catch(e)
{
// This executes in IE7,
// but not IE8, regardless of mode
}

处理计划方案: Short of version detection, this is a difficult issue to work around. If this behavior is essential to a page, updating the page to run in IE8 Standards Mode may be the best approach.