如何把WebBrowser控件到IE9成标准? [英] How to put the WebBrowser control into IE9 into standards?

查看:175
本文介绍了如何把WebBrowser控件到IE9成标准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 即= CoInternetExplorer.Create;
ie.Navigate2(关于:空白);
webDocument = ie.Document;
webDocument.Write(szSourceHTML);
webDocument.Close();
ie.Visible = TRUE;

Internet Explorer中出现,显示我的HTML,它开​​始了为:

 <!DOCTYPE HTML>
< HTML>
&所述; HEAD>
   ...


  

注意: HTML5的标准模式选择,在DOCTYPE HTML


除该文件是不是在IE9标准模式;它在IE8标准模式:


如果我的HTML保存到我的计算机首先:

,然后查看 html文件,IE被放入标准模式:

我的问题是如何更新我的 SpawnIEWithSource(字符串HTML)函数抛出浏览器转化为标准模式?

 无效SpawnIEWithSource(字符串HTML)
{
   变体即= CoInternetExplorer.Create();
   ie.Navigate2(关于:空白);
   webDocument = ie.Document;
   webDocument.Write(HTML);
   webDocument.Close();
   ie.Visible =真;
}


编辑:更详细的,更难理解或可读code样品,不利于进一步的问题可能是:

 的IWebBrowser2即;
CoCreateInstance的(CLASS_InternetExplorer,空,CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,IID_WebBrowser2,即);
ie.AddRef();
ie.Navigate2(关于:空白);IHtmlDocument文档;
dispDoc = ie.Document;
dispDoc.AddRef();
dispDoc.QueryInterface(的IHTMLDocument2,DOC);
dispDoc.Release()
doc.Write(HTML);
doc.Close();
doc.Release();
ie.Visible =真;
ie.Release();


更新

评论者要求在ieblog条目<一个href=\"http://blogs.msdn.com/b/ie/archive/2010/10/19/testing-sites-with-browser-mode-vs-doc-mode.aspx\">Testing用浏览器模式的网站与文件模式:


  

我们可以得到,当HTML内容是一个嵌入式三夏中是如何确定文档模式的描述?似乎是文档方式choosen不同? - 也许由于兼容性原因


MarkSil [MSFT]回复:


  

@Thomas:感谢提出这个问题。 WebBrowser控件决定了DOC模式相同的方式,IE浏览器,因为它包含相同的网络平台(例如对面有IE一个共享的Mshtml.dll和WebBrowser控件主机)。 WebBrowser控件不默认为兼容性视图浏览器模式,这意味着默认文档模式是IE7。这里是一个博客帖子有更多这方面的细节:<一href=\"http://blogs.msdn.com/b/ie/archive/2009/03/10/more-ie8-extensibility-improvements.aspx\">blogs.msdn.com/.../more-ie8-extensibility-improvements.aspx.


要它托马斯回答说:


  

@MarcSil(RE:WebBrowser控件)


  
  

使用注册表项来选择文档模式WebControl的是,它适用于应用程序作为一个整体的问题。我为谷歌SketchUp的插件,你必须WebDialog窗口创建UI - 它只是在一个窗口中WebBrowser控件。但是,当我想强制一个文档模式为我的WebBrowser控件的实例,而不是对所有苏氏的WebBrowser控件作为一个整体,导致的问题。


  
  

所以,我的问题是:你如何控制每个实例文档模式的WebBrowser控件



解决方案

您是否尝试过在你的HTML设置<​​/ P>

 &LT; META HTTP-EQUIV =X-UA-Compatible的内容=IE = 9/&GT;

 &LT; META HTTP-EQUIV =X-UA-Compatible的内容=IE =边缘/&GT;

这意味着最新版本

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 appears, showing my html, which starts off as:

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

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

Except that the document is not in ie9 standards mode; it's in ie8 standards mode:


If i save the html to my computer first:

and then view that html document, IE is put into standards mode:

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;
}


Edit: 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();


Update

Commenter asked on the ieblog entry 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] responded:

@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.

To which Thomas responded:

@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?

解决方案

Have you tried setting in your html the

<meta http-equiv="X-UA-Compatible" content="IE=9" />

or

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

which means latest version

这篇关于如何把WebBrowser控件到IE9成标准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆