gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 01:43:41 28 4
gpt4 key购买 nike

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

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.

托马斯对此回应:

@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 - 如何把IE9的WebBrowser控件纳入标准?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31962511/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com