简体   繁体   中英

How to set the IE Browser mode rather than setting Document mode

How to set the IE Browser mode rather than setting the Document mode? Why Browser mode and Document mode? For what purpose we are using these two different modes?

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />

It will change only document mode. Is it possible to change the IE Browser Mode programmatically ?

The two modes do two different things:

  • The Document mode determines how IE renders the page.

  • The Browser mode determines how IE identifies itself -- that is, its User Agent String.

The X-UA-Compatible flag sets the document mode. There is no way to explicitly set the modes individually via your code; this can only be done manually in the dev tools. ( but see below ‡ )

This means that if you're relying on the User Agent string to identify the browser, then using X-UA-Compatible will give you incorrect results, because the browser is identifying itself differently to how it is actually rendering.

The upshot of all this is that you should avoid using User Agent string to identify the browser; it can lie to you, and often does.

It's also a good idea, if possible, to avoid using X-UA-Compatible to force IE to use compatibility mode -- if you find yourself needing compat mode, it is because your site works better in older IE versions than in newer versions. Given that newer versions are better at being standards-compliant, this probably means that you have bugs in your code that you need to fix. Ideally you should fix those bugs rather than switching to compat mode; compat mode should only be used as a last resort.


( ) It's worth noting that this changes in the forthcoming IE11, which will remove the ability to set the browser and document modes via the dev tools in most cases. The IE devs are trying to reduce the incentive for people to use the compat modes, and encourage people to write more standards-compliant code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM