"Go" http-equiv= "x-ua-compatible" setting IE browser compatibility mode

Source: Internet
Author: User
Tags website server

File compatibility is used to define how IE compiles your Web pages. This file explains file compatibility, how to specify the file compatibility mode for your site, and how to determine which file mode a Web page uses.


Objective

To help ensure that your pages have a consistent look in all future versions of IE, IE8 introduces file compatibility. Introducing an additional compatibility mode in IE6, file compatibility allows you to choose a specific compilation mode when IE renders your Web page.
The new IE to ensure that the Web page in future versions will have a look, IE8 introduced file compatibility. When you introduce an additional compatibility mode,
This article explains the need for file compatibility, lists the file compatibility patterns that existing versions of IE can use, and demonstrates how to select specific compatibility modes.


Understanding the need for file compatibility

Each major version of IE has been added to make the browser easier to use, increase security, and support industry standards. With these as the characteristics of IE, one of the risks is that the old version of the site can not be displayed correctly.

To minimize this risk, IE6 allows Web developers to choose how IE compiles and displays their Web pages. "Quirks mode" is a preset, which causes the page to be displayed in the previous version of the browser's viewpoint, and "Standards Mode" (also known as "strict Mode") features the most complete support for industry standards. However, to take advantage of this enhanced support feature, the Web page must contain the appropriate <! doctype> instructions.

If a webpage does not contain <! doctype> instruction, IE6 will display it as quirks mode. If the page contains a valid <! doctype> Instruction But the browser is not recognizable, IE6 will display it as IE6 standards mode. Because a few sites already contain <! doctype> instructions, the switch to compatibility mode is quite successful. This allows web developers to choose the best time to transfer their pages to standards mode.

As time passed, more websites started using standards mode. They are also beginning to use IE6 's features and functions to detect ie. For example, IE6 does not support Universal Selector(that is, the CSS global selector * {}), some websites use it to do specific correspondence for IE.

When IE7 adds support for a global selector, sites that rely on IE6 features will not be able to detect this new version of the browser. Therefore, those specific correspondence to IE cannot be applied to IE7, resulting in these sites not being displayed as they intended. Since <! Doctype> only supports two compatibility modes, and the affected site owners are forced to update their website to support IE7.

IE8 has more support for industry standards than any previous version of the browser, so pages designed for older browsers may not render as expected. To help alleviate all problems, IE8 introduces the concept of file compatibility, allowing you to select the specific IE version of your Web page design to correspond to. File compatibility adds some new patterns to the IE8 that tell the browser how to parse and compile a Web page. If your page does not display correctly in IE8, you can update your site to support the latest page standards (preferences) or add a meta element to your page to tell IE8 how to compile your page in accordance with the previous version of the browser.

This gives you the option to update your site to support IE8 new features.


Understanding file Compatibility Mode

IE8 supports several file compatibility modes, which have different characteristics and affect the way content is displayed.

emulate IE8 mode indicates IE uses<! Doctype>Instructions to determine how to compile the content. The Standards Mode command is displayed as IE8 standards mode and quirks mode is displayed as IE5 mode. Unlike the IE8 mode,emulate IE8 mode values<! Doctype>Instructions.
emulate IE7 mode indicates IE uses<! Doctype>Instructions to determine how to compile the content. The Standards Mode command is displayed as IE7 standards mode and quirks mode is displayed as IE5 mode. Unlike the IE7 mode,emulate IE7 mode values<! Doctype>Instructions.This is the most recommended compatibility mode for many Web pages.
IE5 mode compiles like IE7 's quirks mode display, and is very similar to what is shown in IE5.
IE7 mode compiles content like IE7 's standards mode display, regardless of whether the page contains<! Doctype>Instructions.
IE8 mode provides the highest level of support for industry standards, includingcascading Style Sheets Level 2.1 specificationAndSelectors API, and limited support forcascading Style Sheets Level 3 specification (working Draft)。
edge mode instructs IE to display content in the highest mode currently available. When using IE8, it is equivalent to IE8 mode. if (assuming) future releases of IE that support a higher compatibility mode, pages using edge mode will display content using the highest mode supported by that version. The same pages will still be displayed as usual when browsing with IE8.

Because edge mode uses the highest mode supported by the IE version to display the content of the Web page viewed, it is recommended to use only the test page and other non-commercial pages.


Specify file compatibility mode

To specify a file mode for your Web page, you need to use the meta element in your Web page to put the x-ua-compatible http-equiv header. The following is a sample designation for emulate IE7 mode compatibility.

<HTML><Head><!--Mimic Internet Explorer 7 -<Metahttp-equiv= "X-ua-compatible"content= "Ie=emulateie7" /><title>My Web Page</title></Head><Body><P>Content goes here.</P></Body></HTML>


Its contents change with the specified page mode, when you want to simulate IE7, specify ie=emulateie7, specify ie=5, ie=7, or ie=8 to select one of the compatibility modes. You can also specify Ie=edge to instruct IE8 to use the highest mode it supports.

The x-ua-compatible header is not case-sensitive. However, in addition to the title element and other meta elements, it must appear before other elements in the header section of the Web page.


Setting up a Web server to specify a preset compatibility mode

Site administrators can define a custom header for the site to preset a specific file compatibility mode for their site. This particular method depends on your Web server. For example, the following Web. config file enables Microsoft Internet information Services (IIS) to define a custom header to automatically compile all pages using IE7 mode.

<?XML version= "1.0" encoding= "Utf-8"?><Configuration><system. WebServer><Httpprotocol><customheaders><Clear/><Addname= "X-ua-compatible"value= "Ie=emulateie7" /></customheaders></Httpprotocol></system.webserver></Configuration>


If you have specified a preset file compatibility mode on the site server, you can specify a different file compatibility mode on individual pages to cover it. The mode precedence specified in the Web page is higher than the mode specified in the server.

Please check your website server for information on specifying a custom header, or read more:

Implementing the META Switch on Apache
Implementing the META Switch on IIS


Determine file compatibility mode

To determine the file compatibility mode for Web pages using IE8 browsing, use the documentmode feature of document object. For example, enter the following code in the IE8 URL column to display the file mode of the current page.

Javascript:alert (document.documentmode);

The documentmode function will return a value corresponding to the current page of the file compatibility mode, for example, if the page is designated to support IE8 mode,Documentmode will return the value "8".

The compatmode feature introduced in IE6 does not support the Documentmode feature introduced in IE8. Applications that are currently built using Compatmode can also function 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 that introduces the following example can support older versions of IE.

Engine=Null;
If(Window.navigator.appName=="Microsoft Internet Explorer")
{
//This is an IE browser. What's the engine in?
If(Document.documentmode)//IE8
Engine=Document.documentmode;
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.
}

Understanding Content Property Values

The value of the content property is resilient when it receives a value that is different from the previously described values. This will give you more control over how IE displays your Web pages. For example, you can set the Content property value to ie=7.5. When you do this, IE attempts to convert this value to version vector and select the closest result. In this example, IE will set it to IE7 mode. The following example shows the state of the pattern set to another value.

<MetaHttp-equiv= "X-ua-compatible"Content= "Ie=4"> <!--IE5 mode-
<MetaHttp-equiv= "X-ua-compatible"Content= "ie=7.5"><!--IE7 mode-
<MetaHttp-equiv= "X-ua-compatible"Content= "Ie=100"><!--IE8 mode-
<MetaHttp-equiv= "X-ua-compatible"content= "Ie=a" >< Span style= "color: #000000;" > <!--ie5 mode -- >

<! Doctype> to determine how to display the Web page --> <meta Http-equiv= "x-ua-compatible" content= "Ie=emulateie7" >

Note: The previous example shows a separate content value. In fact, IE only executes the first x-ua-compatible header in a webpage.

You can also use content properties to specify the file compatibility mode of complex numbers, which can help ensure that your pages will be displayed consistently in future browser versions. To set the file mode of a complex number, set the content properties to determine which mode you want to use. Use semicolons to separate each pattern.

If a specific version of IE support requires more than one compatibility mode, it will be used in the highest available mode listed in the header content properties. You can use this feature to exclude specific compatibility modes, although this is not recommended. For example, the following header excludes IE7 mode.

<meta http-equiv= "x-ua-compatible" content= "ie=5; Ie=8 " />

Conclusion

Compatibility is a very important concern for web designers. While it is best to build a website that does not depend on any Web browser features or functionality at all, it is sometimes impossible to implement. File compatibility mode restricts Web pages to a specific version of IE.

Use the x-ua-compatible header to specify the version of IE that your page supports. Use Document.documentmode to determine the compatibility mode of the page.

By choosing to support a specific version of IE, you can ensure that your page will also show consistency in future browser versions.

---------------------------Original---------------------------

Other:

x-ua-compatible set to Ie=edge is not equal to not set?

Not the same. Some factors will automatically trigger the compatibility document view, this time setting this x-ua-compatible can prevent this automatic triggering behavior

The default behavior is roughly these:

    • List of compatibility views that exist in the registry and automatically switch to Compatibility view when URLs match
    • The corresponding field in the registry specifies that all sites are displayed using Compatibility view
    • DOCTYPE is not specified, the quirks mode is used
    • Have ever encountered an error

Other:

<meta http-equiv = "x-ua-compatible" cotent = "ie=edge,chrome=1"/>

This is a IE8 special tag, used to specify the IE8 browser to simulate a particular version of the IE browser rendering, to solve some of the compatibility problems, such as the specific way to simulate IE7:< meta http-equiv = "X-ua-compatible" Content = "Ie=emulateie7"/> But to my curiosity, there is a value like chrome behind this tag, can IE also emulate chrome? A quick search, only to understand that the original is not Microsoft enhanced IE, but Google did a plug-in: Google Chrome frame (google embedded browser framework GCF). This plugin can make the user's IE browser unchanged, but the user in the Web browsing, actually using the Google Chrome browser kernel, and support IE6, 7, 8 and other versions of IE browser, Google this corner digging real force!


The meta tag mentioned above is used to specify that the page is rendered using the chrome kernel after the GCF is installed. Once the installation is complete, if you want to render a page using GCF, just precede the address of the page with GCF: Yes, for example: gcf:http:// Cooleep.com But what if you want to specify the page default to use GCF for rendering at development time, and if the GCF is not installed and then rendered using the IE kernel?
is to use this tag.

Tag usage:
Read the next Chrome development document (http://www.chromium.org/developers/how-tos/chrome-frame-getting-started) below to briefly explain the syntax of this tag.

1. Most basic usage: add to the head of the page

<meta http-equiv = "x-ua-compatible" cotent = "ie=edge,chrome=1"/>

The effect of this writing is that if the GCF is installed, a GCF is used to render the page, and if the GCF is installed, the highest version of the IE kernel is used for rendering.

2. Modify the HTTP header file method to enable the specified page to render using the GCF kernel:
In the HTTP header file, add the following information: x-ua-compatible:chrome=1
In the Apache server, make sure that the mod_headers and mod_setenvif files are available, and then add the following configuration information to the httpd.conf:

XML Code
<mod_setenvif.c>  < mod_headers.c  >  browsermatch chromeframe GCF  Header append x-ua-compatible "chrome=1" ENV=GCF   </  >  </>  
On IIS7 or later servers, you only need to modify the Web. config file to add the following information:

XML Code
<spanstyle= "color: #000000;"><Configuration>  <system. WebServer>  <Httpprotocol>  <customheaders>  <Addname= "X-ua-compatible"value= "Chrome=1" />  </customheaders>  </Httpprotocol>  </system.webserver>  </Configuration></span>  

"Go" http-equiv= "x-ua-compatible" setting IE browser compatibility mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.