问题
So I know about FEATURE_BROWSER_EMULATION, but either it isn't working for me, or it only controls the Browser Mode and not the Document Mode.
I have a lot of info specific to my case below, but the general question that I think/hope should have an easy answer that applies to lots of people is: How do I get the WebBrowser control to render exactly like whatever version of IE the user has installed? I think this comes down to control over the "Document Mode"
I'm trying to get the WebBrowser control to render HTML the same way IE10 does, without modifying the HTML (because that isn't robust). My app is an email client that displays HTML email, and here is what a typical email from GMail might look like:
<div dir="ltr"><div id="" team-id="21062" dir="ltr"><div id="email-body-container" style="width:96%; padding:0; margin:2%; border:solid 1px #E7E7E7;">
<div id="email-body-header" style="width:94%; padding:3% 3% 2% 3%; background-color:#f5f5f5; border-bottom:solid 1px #eaeaea;">
<img src="http://www.google.com/adwords/htp/static/legacy/adwords_logo_grey_166x28.png" alt="Google AdWords" width="166" height="28" style="outline:none; text-decoration:none; -ms-interpolation-mode: bicubic; display:block;">
</div>
</div></div>
I have that exact HTML in a file named c:\test.htm, and I load it in IE by entering that in the address bar, and then I load it in the webbrowser control using Navigate("c:\\test.htm")
, and they don't render the same.
I know it isn't valid HTML because it doesn't even include an html tag, body tag, etc, but this is how GMail does things and I have no control over that (or other weird stuff email clients do). The only thing I do know is that Internet Explorer always seems to display them nicely (probably most people test with IE, that's why). However, they don't display nicely in the WebBrowser control. Here is the above HTML in IE10 (Win8) and in a simple WinForms app using the WbeBrowser control:
The WinForms app has a scrollbar when one isn't needed, and also the border doesn't match the background color size. Using IE developer tools I can try every combination of Browser Mode (IE7 through IE10) and every combo of Document Mode (standards, quirks, IE7 - IE9 standards) and the only way I can get IE to render like the WebBrowser control is to set the Document Mode to "IE5 quirks". In which case it renders the same as the WebBrowser control even if Browser Mode is set to IE10.
I've set this registry value: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\WindowsFormsApplication2.exe
I've tried setting it to 10000, 10001, 9999, 8888, 9000, and a few other values (decimal, not hex) and they have no effect on this issue. My EXE name is WindowsFormsApplication2.exe, and I've set my build to x64 and confirmed it is running as a 64-bit process, so that I don't have to worry about setting Wow6432Node instead (but I even tried setting that also).
So I'm thinking that only controls the Browser Mode, but not the Document Mode? I tried the obsolete FEATURE_NATIVE_DOCUMENT_MODE setting also, no change.
Note, I tagged this as TWebBrowser also because I originally found this issue using that, but since hardly anyone uses that I made sure I could recreate in a real simple .NET C# WinForms app.
Added May 17th:
Here is a reg export (I deleted everything under HKCU just to make sure it wasn't overriding anything in HKLM):
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"prevhost.exe"=dword:00001f40
"HelpPane.exe"=dword:00002710
"sllauncher.exe"=dword:00001f40
"test.exe"=dword:00002710
"iexplore.exe"=dword:00002711
"windowsformsapplication2"=dword:00002710
"windowsformsapplication2.exe"=dword:00002710
"test"=dword:00002710
Here is what my "test.exe" looks like in Task Manager:
回答1:
According to MSDN
10001 (0x2711) Internet Explorer 10. Webpages are displayed in IE10 Standards
mode, regardless of the !DOCTYPE directive.
10000 (0x2710) Internet Explorer 10. Webpages containing standards-based
!DOCTYPE directives are displayed in IE10 Standards mode.
Default value for Internet Explorer 10.
The MSIE on your machine uses 0x2711
, which means it will always renders the document in standard mode. Your application uses 0x2710
. As your test document does not have a !doctype
, it will be rendered in Quirks mode. This is the root cause why the webpage looks differently.
Note that windowsformsapplication2.exe
is a valid entry for Registry.
Both MSIE and my app have a scrollbar there. Sorry, I have no idea how to make the scrollbar looks exactly the MSIE does yet. But I'm sure the look and feel of scrollbar has nothing to do with FEATURE_BROWSER_EMULATION
来源:https://stackoverflow.com/questions/23690072/webbrowser-control-set-document-mode