com - 如何把WebBrowser 控件纳入IE9 标准?

标签 com html automation standards internet-explorer-9

我正在使用自动化(即 COM 自动化)在 Internet Explorer (9) 中显示一些 HTML:

ie = CoInternetExplorer.Create;
ie.Navigate2("about:blank");
webDocument = ie.Document;
webDocument.Write(szSourceHTML);
webDocument.Close();
ie.Visible = True;

出现 Internet Explorer,显示我的 html,开头为:

<!DOCTYPE html>
<HTML>
<HEAD>
   ...

Note: the html5 standards-mode opt-in doctype html

除了文档不是ie9标准模式;它处于 ie8 标准模式: alt text


如果我先将 html 保存到我的计算机:

alt text

然后查看那个html文件,IE进入标准模式:

alt text

我的问题是如何更新我的 SpawnIEWithSource(String html) 函数以使浏览器进入标准模式?

void SpawnIEWithSource(String html)
{
   Variant ie = CoInternetExplorer.Create();
   ie.Navigate2("about:blank");
   webDocument = ie.Document;
   webDocument.Write(html);
   webDocument.Close();
   ie.Visible = true;
}

编辑:一个更冗长、更难理解或可读的代码示例,对进一步的问题可能没有帮助:

IWebBrowser2 ie;
CoCreateInstance(CLASS_InternetExplorer, null, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_WebBrowser2, ie);
ie.AddRef();
ie.Navigate2("about:blank");

IHtmlDocument doc;
dispDoc = ie.Document;
dispDoc.AddRef();
dispDoc.QueryInterface(IHTMLDocument2, doc);
dispDoc.Release()
doc.Write(html); 
doc.Close();
doc.Release();
ie.Visible = true;
ie.Release();

更新

评论者在 ieblog 条目上提问 Testing sites with Browser Mode vs. Doc Mode :

Can we get a description of how the document mode is determined when the HTML content is within an embedded webcontrol? Seems to be that the document mode is choosen differently - maybe for compatibility reasons?

MarkSil [MSFT] 回应:

@Thomas: Thanks for raising that question. The WebBrowser Control determines the doc mode the same way that IE does because it contains the same web platform (e.g. there is one shared mshtml.dll across IE and WebBrowser Control hosts). The WebBrowser Control does default to the Compatibility View browser mode, which means that the default doc mode is IE7. Here is a blog post with more detail on this: blogs.msdn.com/.../more-ie8-extensibility-improvements.aspx.

Thomas 回应:

@MarcSil (re: WebBrowser Control)

The problem with using registry entries to select document mode for WebControl is that it applies to the application as a whole. I write plugins for Google SketchUp where you have WebDialog windows to create UIs - it's just a WebBrowser control in a window. But that leads to problems as I want to force a document mode for my instance of the WebBrowser control, not for all of SU's WebBrowser controls as a whole.

So, my question is: how do you control the document mode per instance for a WebBrowser control?

最佳答案

你试过在你的html中设置

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

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

表示最新版本

关于com - 如何把WebBrowser 控件纳入IE9 标准?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4097593/

相关文章:

c++ - 如何从非托管 C++ 引用 com exe?

windows - 64 位 dll 寄存器

Javascript限制输入文件上传的文件数量

unit-testing - Vb6 UI自动化测试工具?

.net - 这是为 COM 注册 .NET 类型的一种可能方法吗

c# - 将反射与 COM Interop 结合使用

javascript - 如何更改麦克风实时音频的播放速度(使用缓冲区)?

html - Flexbox "nowrap"值不起作用

windows - 如何在 Windows 中自动启动 XAMPP 和 Laravel 项目

windows - 如何递归搜索文件但仅对使用批处理文件找到文件的实例进行操作?