How do I programatically set the Browser Mode in Internet Explorer - cross-browser

IE has a Browser Mode and Document Mode and I can only seem to set the Document Mode programatically by adding this:
<meta http-equiv="X-UA-Compatible" content="IE=5" />
This sets Document Mode correctly for me, but I need the Browser Mode to change to Compatibility View. My site only works with these two settings this way. I've tried changing the DocType and other meta settings but nothing seems to work. I've also confirmed my IE settings under Tools->Compatibility Settings have all 3 check-boxes unchecked and nothing in the listbox.
My website is ASP.NET 2.0 running on IIS6 (Windows 2003 Server).
Here is a simple sample site that demonstrates this. Open this in IE10 and then look at the developer tools (F12):
<html>
<head>
<title>This is the title</title>
<meta http-equiv="X-UA-Compatible" content="IE=5" />
<script type="text/jscript" language="jscript">
function foo() {
alert("document.documentMode: " + document.documentMode +
"\n\rdocument.compatMode: " + document.compatMode +
"\n\rnavigator.userAgent: " + navigator.userAgent);
}
</script>
</head>
<body onload="javascript:foo();">
This is a test site
</body>
</html>

First, requisite chiding: if this is your site, you should fix it to work with modern standards.
That said, you're likely accessing this site in such a way that it is loaded in the Intranet Zone, and you said that you've disabled the option to display intranet sites in compatibility view in compatibility view settings. (I believe it is enabled by default.)
Intranet Zone settings override your page's settings, so you have to re-enable that option.

Related

document.body.innerHTML fails on IE when setting it to "<P><HR>"

Our application uses embedded IE control, and we noticed that setting:
document.body.innerHTML it to <P><HR> causes an OLE exception "Unknown runtime error".
I could reproduce this in the IE browser itself (IE version 8).
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Untitled</title>
<script>
function load(){
// alert(document.body.innerHTML)
document.body.innerHTML = '<P><HR>';
}
</script>
</head>
<body onload="load()">
</body>
</html>
If the body.innerHTML is set to <P></P><HR> all is good. but the problem that the HTML strings are coming from a DB. Why is this happening and how can this be fixed?
EDIT: The code works fine on IE11. but the problem exists on systems with IE8. no matter if I change FEATURE_CONTROL_BROWSER_EMULATION key. Is there anything could be done for IE8?
The MSIE WBC (Web browser control), whether hosted by a Delphi or .net desktop application use IE7 Emulation by default.... To determine which IE emulation mode your hosted WBC is using add the following snippet to the onload event.
alert(document.documentMode?document.documentMode:'n/a');
To make your WBC use the IE emulation mode you need to add a registry entry in the FEATURE_CONTROL_BROWSER_EMULATION key in the registry.
see the documentation here - https://msdn.microsoft.com/en-us/library/ms537184%28v=vs.85%29.aspx
to get your invalid markup to work.
1. use a valid document type declaration. ().
2. change your FEATURE_CONTROL_BROWSER_EMULATION value in the registry to emulate IE8 or higher....
Ideally you want your WBC to emulate IE11 and modern web standards for html5, but that may not be possible if your existing markup is pre-HTML5,CSS 3.(viz: your markup was developed for IE6 on an intranet website, using DHTML (the early MS versions of HTML).

IE11 browser showing document mode as 5(default)

Im using bootstrap framework and using the follwoing docttype and meta tag.
<!DOCTYPE html>
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
Here IE showing document mode as 5(default), mean while all the UI got disturbed, any solution for showing IE=edge.
Thanks
Your IE options are probably set to display Intranet sites in Compatibility View. I tested IE 11 at the official Bootstrap site and it was set to Edge using X-UA meta tag.
From the MS documentation:
Via intranet compatibility settings: The "Display intranet sites in Compatibility View" box is checked in the Compatibility View settings."

Why does IE9 opens in Document Mode as IE7 standards?

When I open a webpage in IE9 with DOCTYPE as
<!DOCTYPE html>
It opens Document Mode as IE7 standards.
I need default IE9 standards on opening the page.
How to correct this document mode problem?
A screenshot of how it comes in IE browser developer tool
Try this answer: https://stackoverflow.com/a/13524518/1679310.
Summary, give the IE browser more information in the meta tag:
<!DOCTYPE html>
<html>
<head>
<title>My Web</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
Edit Note: As Olly Hodgson mentioned, the proper option is IE=edge, as currently stated in the above snippet. Below is the original, also working version:
<meta http-equiv="X-UA-Compatible" content="IE=100" />
There can be multiple reasons why it could be parsing the document under IE7 standard:
The server is sending a X-UA-Compatible header for IE7 in the HTTP response of the document. Check the server response headers using a tool like Fiddler.
The HTML document is setting a meta tag with the X-UA-Compatible property value for IE7.
The page is being detected automatically by IE for opening in "Compatibility view". Note here that by default all intranet sites are viewed in "Compatibility view" in IE. Uncheck the checkbox "Display intranet sites in Compatibility view" under Tools -> Compatibility view settings in IE. The "Display all websites in Compatibility view" should be unchecked too.
You used the Developer tools and explicitly set to view the page to render in "IE7 standards" mode. Note that this will only occur on a per client basis though.
Update 2016-01-28
As #Gordon pointed out in the comments below, another reason can be that the network administrator has set the site for compatibility view as a Group Policy on the network.
The only resolution in that case is to contact the network administrator to remove the site from the Group Policy. See HTML1203 here.
You can set this in the web.config as well.
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=edge" />
</customHeaders>
</httpProtocol>
Does your page contain the meta tag for forcing IE7?
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
this will force the page to use IE7 compatibility.
Just wanted to share that if your web server is Apache2 you could set the Response header like below in your VirtualHost configuration which will also resolve the issue.
Header set X-UA-Compatible "IE=edge"
The issue appears to be specific to the combination of IE9 and compatibility mode. For us, we cannot disable compatibility mode since it is a SharePoint 2013 site and IE11 must run in compatibility mode to edit pages, but IE9 was behaving as you are showing. Setting the X-UA-Compatible to "IE=edge" in a meta tag did fix our issue, although setting the value to IE=10 did not affect our behavior. We also have the same doctype.
If your project is ASP.NET MVC, make sure that you add the:
<meta http-equiv="X-UA-Compatible" content="IE=edge">
tag into your Layout (template) page. I just spent two hours debugging and tweaking, only to realize that I had only added that meta tag into my child pages. As soon as I added it to my layout page, the browser loaded in EDGE mode perfectly.

IE8 compatibility mode button missing

I'm developing a website using Umbraco and I'd like to flick between IE8 and IE7 using the compatibility button, but it's hidden. It is an internal address but I've not had the problem with similar sites on the same server. (The only difference is this is using a 'non-standard' port 8080, I shouldn't think that would make a difference?)
I've checked the following blog post; Compatibility View Button Missing in IE8
Which states,
The Compatibility View button will be missing for the following
reasons,
If you’re viewing any webpage and you have the ‘Display all websites
in Compatibility View’ checkbox selected in Tools > Compatibility View
Settings.
If you’re viewing a webpage that is included on the
Microsoft-supplied compatibility view updates list and you have the
‘Include updated website lists from Microsoft’ checkbox selected in
Tools > Compatibility View Settings,
If you’re viewing an intranet page and you have the ‘Display intranet sites in
Compatibility View’ checkbox selected in Tools > Compatibility View Settings.
If you’ve toggled either the ‘Document Mode’ or ‘Browser Mode’ settings
via the Developer Toolbar.
If you’re viewing a page that has declared it’s “ready” for Internet Explorer 8.
My site/browser settings don't fall into any of these categories so I can only presume there's more factors involved.
I'm using the following DOCTYPE in all of my pages,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
I can force IE to render using the latest version by including,
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
But this doesn't give me the functionality to switch browser modes via the button.
this is to make html5 to work in IE8,9
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js" type="text/javascript"></script>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/ie7-squish.js" type="text/javascript"></script>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
<![endif]-->
Hope this will help
If you are indeed including this tag in your page
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
then that is why the button is missing. You've communicated to IE that the site is (supposedly) compatible with its standards rendering mode. Hence it will not display a button to the user for compatibility mode because that would (supposedly) allow the user to accidentally switch the rendering mode, potentially mangling the visual layout of your site.
Ironically, I've often had the opposite problem. The button frequently shows up when I don't want it to. The criteria for whether or not it shows up seems very finicky. Should you every want the opposite behavior (no button being present) I recommend making the above meta tag the first tag of your header.

Force "Internet Explorer 8" browser mode in intranet

There are "Internet Explorer 8", "Internet Explorer 8 Compatibility Mode", and IE7 mode in IE8.
However, the default setting in IE make all intranet website use "IE8 Compatibility Mode" even I have setted doctype, the meta tag, http header as suggested to force it into IE8 mode.
I have
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
and
<meta http-equiv="X-UA-Compatible" content="IE=8" >
But it still goes into "IE8 Compatibility Mode", without any changes in IE setting.
How to force it into pure "IE8" mode, without change any browser's setting?
PS. I am not talking "document mode" here.
Seem that MSFT has not consider a large intranet environment that we have many different web application running inside.
There is no way to bypass the IE8 setting, according to somewhere I read on MSDN forum.
So, I will have to beg my system administrators to put some new group policies to change "Compatibility View" setting and the value and prevent user change the value, until MSFT discover this bug and fix it.
From an MSDN blog post (emphasis theirs): "Browser Mode is chosen before IE requests web content. This means that sites cannot choose a Browser Mode."
It is possible to override the compatibility mode in intranet. Just add the below code to the web.config. Worked for me with IE9.
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=edge" />
</customHeaders>
</httpProtocol>
You'll have to make some adjustments to IE.
Here they are.....
In Internet Options / Local Intranet / Sites
Under : Local Intranet inside Sites, uncheck "Automatically detect intranet network".
Then select only "Include all network paths (UNCs)
See attached screenshots
I found the answers here hard to follow, so here's the important information in a nutshell:
If your intranet uses default settings for IE, IE7 Standards Mode is enforced for intranet sites regardless of any website settings.
From this:
Compatibility View and the Enterprise
A large number of line-of-business
websites are Internet Explorer 7
capable today. In order to preserve
compatibility, Internet Explorer 8
ships with smart defaults based on
zone evaluation. In the default state,
all sites on the public internet
display in Internet Explorer 8
Standards mode (Compatibility View
off) and all intranet websites
display in Internet Explorer 7
Standards mode (Compatibility View
on).
Let’s look at some examples. If you
navigate to sites on your local
intranet like http://myPortal and
http://sharepoint/sites/mySite,
Internet Explorer 8 identifies itself with a User Agent string of
‘7’, Version Vector of ‘7’, and
displays webpages that trigger
standards mode in Internet Explorer 7
Standards mode. This combination
allows webpages that worked correctly
in Internet Explorer 7 to continue to
do so in IE8.
To override the Compatibility View settings for intranet or all websites you need to make IE8 emulate itself.
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" >
Set a custom HTTP header instead of using the <meta... in the <head> section. These are supposed to be equivalent, but I have seen that an X-UA-Compatible HTTP header from the server will override IE 8's "Display intranet sites in Compatibility View" setting, where the <meta... element would not.
If you are using .NET, I have the answer for you:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" >
Web.Config:
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=8" />
</customHeaders>
</httpProtocol>
Read somewhere that the DOCTYPE declaration must be the very first line. No comments of any kind, nor empty lines.
In combination with setting the HTTP Response Headers, this worked for me. Browser Mode went from "IE9 Compatibility Mode" to just "IE9 Mode".
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation
IntranetCompatibilityMode 1-->0
In order for the META declaration to work, the doctype has to be the simplified version:
<!DOCTYPE html>
Not the longer statement in Dennis' question.
This combo did the trick for me:
<!DOCTYPE HTML>
<HEAD>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" >
</HEAD>
at least IE developer tools reports IE9 Compat View, IE8 standards
just for kicks i tried EmulateIE7 and that worked as well.
simplifying the extended !DOCTYPE was key.
You need remove port number from your domain site name
site:1180/index/
If browser see port number in url - hi "think", that's is intranet.
setup your dns server for friendly urls - site.com/index and it work OK
The answer marked as "correct" is technically correct but suggests that there is no solution to the real issue being faced by most people that is: "how do I properly show on IE8, with compatibility mode enabled, a web application which does not support compatibility mode?".
<!DOCTYPE HTML>
<HEAD>
<meta http-equiv="X-UA-Compatible" content="Edge" >
</HEAD>
this worked for me on several workstations.
If the above code is implemented on application side, IE8 appears to behave as if it was not in compatibility mode, even though it will still show browser mode as compatibility mode.