How do I turn off Compatibility View on the IE WebBrowserControl in a WinForms app?
There is no way to do this other than configuring the following registry settings:
HKLM\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
or if it's a 32 bit app on 64 bit Windows:
HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION`
These settings aren't surfaced in the WebBrowser
control.
For more information please see:
What IE compatibility mode does the webbrowser control use?
In case the link dies:
You create a DWORD
value matching the name of your executable and set this value to one of:
7000: Pages containing standards-based
<!DOCTYPE>
directives are displayed in IE7 mode.
8000: Pages containing standards-based<!DOCTYPE>
directives are displayed in IE8 mode
8888: Pages are always displayed in IE8 mode, regardless of the<!DOCTYPE>
directive. (This bypasses the exceptions listed earlier.)
9000: Use IE9 settings!
9999: Force IE9
For example:
From my own experiments with IE9:
9000 - inherits the compatibility mode set in IE9's global compatibility mode setting. i.e.:
9999 - forces IE9 out of compatibility mode in the host application regardless of the globally configured compatibility mode setting
Your application would probably need to detect which underlying IE version is available to determine which value to use:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version
or if it's a 32 bit app on 64 bit Windows:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Version
There's also this older article from when IE8 came out which is worth a look:
More IE8 Extensibility Improvements
You can also configure these settings on a per user basis under:
HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
How to programmatically turn off quirks mode in IE8 WebBrowser control?
I think the issue you're facing is described in IEBlog: WebBrowser Control Rendering Modes in IE8:
While webmasters can easily alter
their site to render properly in the
new version of IE, many software
vendors do not have the resources to
instantly push out new versions of
their applications with updated
internal pages.
In order to ensure that these existing
applications remain in working order,
IE8 renders pages running within
instances of the WebBrowser control in
IE7 Standards Mode by default.
Here I should note that the comments on the page say the above is incorrect, and that "IE8 renders pages running within instances of the WebBrowser control in IE7 Strict Mode OR Quirks mode by default, depending on the page's doctype."
The solution is as follows:
When an executable loads an instance
of the WebBrowser control it scans the
registry to check whether the
executable wants IE7 Standards or IE8
Standards mode....
To run in IE8 Standards Mode insert
the following registry value:
[HKEY_CURRENT_USER\Software\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_NATIVE_DOCUMENT_MODE]
"MyApplication.exe"=dword:13880
In both of these instances,
MyApplication.exe should be replaced
with the name of the executable that
will be running WebBrowser controls in
a specified mode.
So it sounds like the "programmatic" solution is to write a key in the registry saying you want IE8 Standards mode for WebBrowser
controls in your specific application.
Set WebBrowser control compatibility mode isn't working
While the this question isn't exactly a duplicate of that one, the same code has apparently helped to solve the issue with the WebBrowser
feature control (FEATURE_BROWSER_EMULATION
).
How can I get the WebBrowser control to show modern contents?
Note: The post is about WebBrowser control, however, for all the new
.NET projects the main solution is using
WebView2.
To learn more, take a look at this post:
- Getting started with WebView2.
WebBrowser Control
The WebBrowser
control uses the same Internet Explorer version which is installed on your OS but it doesn't use the latest document mode by default and shows content in compatibility mode.
Symptom - As a symptom, the site works properly in Internet Explorer or other browsers, but WebBrowser
control doesn't show the site well and for some sites it shows script errors.
Solution - You can tell the WebBrowser
control to use the latest document mode without compatibility mode in WebBrowser
control. You can follow instructions here to disable the setting using registry.
[Reference: Browser Emulation]
Apply Browser Emulation setting using code
If you want to apply the settings using code, run the following code once:
using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
true))
{
var app = System.IO.Path.GetFileName(Application.ExecutablePath);
key.SetValue(app, 11001, Microsoft.Win32.RegistryValueKind.DWord);
key.Close();
}
In above code, I've used 11001
which means IE11 Edge mode.
Internet Explorer 11. Webpages are displayed in IE11 edge mode,
regardless of the declared !DOCTYPE directive. Failing to declare a
!DOCTYPE directive causes the page to load in Quirks.
Apply the Browser Emulation setting manually
Open Registry editor and browse HKEY_CURRENT_USER
, go to the following key:
Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
Add the following values:
"YourApplicationFileName.exe"=dword:00002af9
"YourApplicationFileName.vshost.exe"=dword:00002af9
(In older versions of Visual Studio you needed to add vshost.exe value as well, when you run your program in Visual Studio.)
To create entries right click on an empty area of the right pane, then in the window which appears after selecting dword
value, choose hexadecimal and enter 2af9
:
In above steps, I've used 11001
which means IE11 Edge mode.
Use WebViewCompatible Control for Windows Forms
You can also use the new WebViewCompatible control for Windows Forms. You can see simple steps to use here: Replace WebBrowser control by new WebView Compatible control for Windows Forms.
WebViewCompatible
uses one of two rendering engines to support a broader set of Windows clients:
On Windows 10 devices, the newer Microsoft Edge rendering engine is used to embed a view that renders richly formatted HTML content from a remote web server, dynamically generated code, or content files.
On devices running older versions of Windows, the System.Windows.Controls.WebBrowser is used, which provides Internet Explorer engine-based rendering.
Note:
WebView2
is a replacement forWebView
andWebViewCompatible
.
Set X-UA-Compatibile meta tag
In case that you have access to the html content of the page and you can change the content (for example it's a local html file, or the site belong to yourself) then you can set X-UA-Compatibile
meta tag in the head
like: <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
.
Use other Browser Controls
You can rely on other browser controls like CefSharp
.
MSIEs WebBrowser control hosted in winforms app runs in compatibility mode
I have not tested this, but how about using the META tag, along with the HTTP-EQUIV attribute, to set the X-UA-COMPATIBLE
value to IE=8
, which instructs the web browser to display a page in IE 8 standards mode. An example would be:
<meta http-equiv="X-UA-Compatible" content="IE=8" />
From this line in the following article it seems that this should work.
By default, applications hosting the
WebBrowser Control open
standards-based pages in IE7 mode
unless the page contains an
appropriate X-UA-Compatible header.
You can change this by adding the name
of the application executable file to
the FEATURE_BROWSER_EMULATION feature
control key and setting the value
accordingly.
How to disable compatibility view settings?
I think this is what you need. There are other discussions about similar issues on SO here and here. I think the only way to change the settings programmatically would be to edit the registry with code.
Related Topics
Can a Web User Control (.Ascx) Use a CSS File for Styling
Good Resource to Learn Bdd, Tdd (Ruby , C#, JavaScript)
Java Equivalents of C# String.Format() and String.Join()
How to Get Timestamp of Tick Precision in .Net/C#
Data Binding in Wpf User Controls
Biginteger to Hex/Decimal/Octal/Binary Strings
How to Test for the Presence of an Action Filter with Constructor Arguments
Best Way to Deploy Visual Studio Application That Can Run Without Installing
Cross Platform (PHP to C# .Net) Encryption/Decryption with Rijndael
Dynamically Setting CSS Values Using ASP.NET
Upload File Through C# Using JSON Request and Restsharp
Class with Single Method -- Best Approach
Are Static Methods Thread Safe
Use Linq to Group a Sequence of Numbers with No Gaps