如何把WebBrowser控件转入IE9进入标准? [英] How to put the WebBrowser control into IE9 into standards?
问题描述
我使用自动化(即COM自动化)在Internet Explorer(9)中显示一些HTML:
i am using automation (i.e. COM automation) to display some HTML in Internet Explorer (9):
ie = CoInternetExplorer.Create;
ie.Navigate2("about:blank");
webDocument = ie.Document;
webDocument.Write(szSourceHTML);
webDocument.Close();
ie.Visible = True;
Internet Explorer出现,显示我的html,开头为:
Internet Explorer appears, showing my html, which starts off as:
<!DOCTYPE html>
<HTML>
<HEAD>
...
strong> html5 standard-mode opt-in doctype
html
该文件不在ie9标准模式;它在ie8标准模式:
Except that the document is not in ie9 standards mode; it's in ie8 standards mode:
如果我先将html保存到我的计算机:
If i save the html to my computer first:
,然后查看该 html文档,将IE放入标准模式:
and then view that html document, IE is put into standards mode:
我的问题是如何更新我的 SpawnIEWithSource(String html)
函数将浏览器转换为标准模式?
My question is how update my SpawnIEWithSource(String html)
function to throw the browser into standards mode?
void SpawnIEWithSource(String html)
{
Variant ie = CoInternetExplorer.Create();
ie.Navigate2("about:blank");
webDocument = ie.Document;
webDocument.Write(html);
webDocument.Close();
ie.Visible = true;
}
,不太容易理解或可读的代码示例,这不会进一步的问题可能是:
A more verbose, less understandable or readable code sample, that doesn't help further the question might be:
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();
更新
$ b b $ b
评论者询问了ieblog条目使用浏览器模式与文档模式测试网站:
我们可以获得当HTML内容在嵌入式Web控制中时如何确定文档模式的描述吗?
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]回应:
MarkSil [MSFT] responded:
@ Thomas:感谢你提出这个问题。 WebBrowser控件确定doc模式与IE的方式相同,因为它包含相同的Web平台(例如,在IE和WebBrowser控制主机上有一个共享的mshtml.dll)。 WebBrowser控件默认使用兼容性视图浏览器模式,这意味着默认文档模式是IE7。这里是一个更详细的博客文章: blogs.msdn.com /.../ more-ie8-extensibility-improvements.aspx 。
Thomas回应:
@MarcSil(re:WebBrowser Control)
@MarcSil (re: WebBrowser Control)
使用注册表项来为WebControl选择文档模式的问题是它作为一个整体应用于应用程序。我为Google SketchUp编写插件,其中有WebDialog窗口来创建UI - 它只是窗口中的WebBrowser控件。但是这导致问题,因为我想强制文档模式的WebBrowser控件的实例,而不是所有的SU的WebBrowser控件作为一个整体。
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.
所以,我的问题是:如何控制WebBrowser控件的每个实例的文档模式?
So, my question is: how do you control the document mode per instance for a WebBrowser control?
推荐答案
您是否尝试在HTML中设置
Have you tried setting in your html the
<meta http-equiv="X-UA-Compatible" content="IE=9" />
或
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
表示最新版本
这篇关于如何把WebBrowser控件转入IE9进入标准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!