微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

com – 如何将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;

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

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

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

除了文档不在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;
}

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

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: 07001.

托马斯回答说:

@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" />

这意味着最新版本

原文地址:https://www.jb51.cc/html5/169392.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。