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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/html5/169392.html

猜你在找的HTML5相关文章