相关疑难解决方法(0)

如何将WebBrowser控件放入IE9标准?

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

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

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

<!DOCTYPE html>
<HTML>
<HEAD>
   ...
Run Code Online (Sandbox Code Playgroud)

注意: html5标准模式选择加入doctypehtml

除非文件不符合ie9标准模式; 它是在ie8标准模式下: 替代文字


如果我先将html保存到我的电脑:

替代文字

然后查看那个 html文档,将IE放入标准模式:

替代文字

我的问题是如何更新我的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;
}
Run Code Online (Sandbox Code Playgroud)

编辑:一个更详细,更不易理解或可读的代码示例,这无助于进一步提出问题可能是:

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(); …
Run Code Online (Sandbox Code Playgroud)

com standards html5 automation internet-explorer-9

27
推荐指数
2
解决办法
3万
查看次数

标签 统计

automation ×1

com ×1

html5 ×1

internet-explorer-9 ×1

standards ×1