File compatibility is used to define how IE can compile your webpage. This file explains file compatibility, how to specify the file compatibility mode of your website, and how to determine the file mode that a webpage uses.
Preface
To help ensure that your web pages have consistent appearances in all future IE versions, IE8 introduces file compatibility. Introduce an additional compatibility mode in IE6. File compatibility enables you to select a specific compilation mode when IE presents your webpage.
The new IE introduces file compatibility in order to ensure that the webpage will have an appearance in future versions. When you introduce an additional compatibility mode,
This article describes the necessity of file compatibility, lists the file compatibility modes available for existing version IE, and demonstrates how to select a specific compatibility mode.
Understanding File compatibility mode
IE8 supports several file compatibility modes, which have different features and affect the way the content is displayed.
• Emulate IE8 mode indicates IE usage<! DOCTYPE>Command to determine how to compile the content. The Standards mode command is displayed as IE8 Standards mode, and the quirks mode is displayed as IE5 mode. Unlike IE8 mode, Emulate IE8 mode<! DOCTYPE>Command.
• Emulate IE7 mode indicates IE usage<! DOCTYPE>Command to determine how to compile the content. The Standards mode command is displayed as IE7 Standards mode and the quirks mode is displayed as IE5 mode. Unlike IE7 mode, Emulate IE7 mode<! DOCTYPE>Command. This is the most recommended compatibility mode for many web pages.
• The content compiled by IE5 mode is similar to the display of IE7 quirks mode, which is similar to that displayed in IE5.
• The content compiled by IE7 mode is like the display of IE7 standards mode, regardless of whether the webpage contains<! DOCTYPE>Command.
• IE8 mode provides the highest support for industry standards, including W3C Cascading Style Sheets Level 2.1 Specification and W3C Selectors APIs, and limited support for W3C Cascading Style Sheets Level 3 Specification (Working Draft ).
• Edge mode indicates that IE displays content in the currently available highest mode. When IE8 is used, it is equivalent to IE8 mode. If (assuming) IE that supports higher compatibility mode will be released in the future, pages that use Edge mode will use the highest mode supported by this version to display the content. The same pages will still be displayed as usual when you use IE8 for browsing.
BecauseEdge modeUse thisIEThe maximum mode supported by the version to display the content of the web page. We recommend that you use only the test page and other non-commercial pages.
File compatibility mode
To specify the file mode for your webpage, you must useMetaAdd the element to the X-UA-Compatible http-equiv header. The following is an example of Emulate IE7 mode compatibility.
<Html>
<Head>
<! -- Mimic Internet Explorer 7 -->
<Meta http-equiv = "X-UA-Compatible" content = "IE = EmulateIE7"/>
<Title> My Web Page </title>
</Head>
<Body>
<P> Content goes here. </p>
</Body>
</Html>
Its content changes with the specified page mode. To simulate IE7, specifyIE = EmulateIE7, SpecifyIE = 5, IE = 7, OrIE = 8To select a compatibility mode. You can also specifyIE = edgeTo indicate that IE8 uses the highest mode it supports.
The X-UA-compatible header is case-insensitive. However, apart from the title element and itsMetaIt must appear before other elements in the header section of the webpage,
Set the website server to specify the default compatibility mode
Website administrators can define a custom header for a website to preset a specific file compatibility mode for their website. This specific method depends on your website server. For example, the following web. config file enables Microsoft Internet Information Services (IIS) to define a custom header to automatically use IE7 mode to compile all web pages.
<? Xml version = "1.0" encoding = "UTF-8"?>
<Configuration>
<System. webServer>
<HttpProtocol>
<CustomHeaders>
<Clear/>
<Add name = "X-UA-Compatible" value = "IE = EmulateIE7"/>
</CustomHeaders>
</HttpProtocol>
</System. webServer>
</Configuration>
If you have specified a preset file compatibility mode on the website server, you can specify different file compatibility modes on individual pages to overwrite it. The pattern priority specified on the webpage is higher than the pattern specified on the server.
Determine file compatibility mode
To determine the file compatibility mode when a webpage uses IE8, use the documentMode function of document object. For example, enter the following code in the IE8 URL column to display the file mode on the current page.
Javascript: alert(document.doc umentMode );
DocumentModeThe function returns a value corresponding to the file compatibility mode of the current page. For example, if the webpage is specified to support IE8 mode,DocumentModeThe return value"8".
The compatMode function introduced in IE6 does not supportDocumentModeFunction. Currently usedCompatModeThe created applications can also work in IE8, but they must be updated to use documentMode.
If you want to use JavaScript to determine the compatibility mode of a file, the code introduced in the following example can support the earlier version of IE.
Engine = null;
If (window. navigator. appName = "Microsoft Internet Explorer ")
{
// This is an IE browser. What mode is the engine in?
If (document.doc umentMode) // IE8
Engine = document.doc umentMode;
Else // IE 5-7
{
Engine = 5; // Assume quirks mode unless proven otherwise
If (document. compatMode)
{
If (document. compatMode = "CSS1Compat ")
Engine = 7; // standards mode
}
}
// The engine variable now contains the document compatibility mode.
}
Recognize content attribute values
The content property value is flexible when receiving a value different from the previously described value. This gives you more control over how IE displays your webpage. For example, you can set the content property value to IE = 7.5. When you do this, IE tries to convert the value to version vector and select the closest result. In this example, IE sets it to IE7 mode. The following example shows how this mode is set to another value.
<Meta http-equiv = "X-UA-Compatible" content = "IE = 4"> <! -- IE5 mode -->
<Meta http-equiv = "X-UA-Compatible" content = "ie= 7.5"> <! -- IE7 mode -->
<Meta http-equiv = "X-UA-Compatible" content = "ie= 100"> <! -- IE8 mode -->
<Meta http-equiv = "X-UA-Compatible" content = "IE = a"> <! -- IE5 mode -->
<! -- This header mimics Internet Explorer 7 and uses
<! DOCTYPE> to determine how to display the Web page -->
<Meta http-equiv = "X-UA-Compatible" content = "IE = EmulateIE7">
Note::The preceding example shows a separate content value. In fact, IE only executes the first X-UA-Compatible header on the webpage.
You can also use the content attribute to specify the compatibility mode of the complex file. This helps ensure that your web page will be displayed in a consistent manner in future browser versions. To set the file mode of the plural number, set the content attribute to identify the mode you want to use. Use semicolons to separate modes.
If a specific version of IE supports more than one compatibility mode, use the most available mode listed in the header content attribute. You can use this feature to exclude specific compatibility modes, although this is not recommended. For example, the following header will exclude IE7 mode.
<Meta http-equiv = "X-UA-Compatible" content = "IE = 5; IE = 8"/>
Conclusion
Compatibility is an important concern for web designers. Although it is best to create a website that does not depend on any web browser features or functions, sometimes this is impossible. In File compatibility mode, the webpage can be restricted to IE of a specific version.
Use the X-UA-Compatible header to specify the IE version supported by your page. UseDocument.doc umentModeDetermine the page compatibility mode.
If you select IE to support a specific version, you can ensure that your page will be consistent in future browser versions.
Set IE compatibility mode