WPF WebBrowser 不会显示 Google 个地图

WPF WebBrowser won't show Google Maps

这是这个问题的后续问题:

Load local HTML file in a C# WebBrowser

我通过简单地复制此 link:

中的示例创建了一个 html 文件

https://developers.google.com/maps/documentation/javascript/examples/marker-simple

当我 运行 通过双击打开常规网络浏览器(即 Firefox)的文件时,它可以工作。然后我将 HTML 添加到我的 sln,并将文件的 属性 更改为始终复制到输出目录。然后我尝试 运行 像这样:

string curDir = Directory.GetCurrentDirectory();
webBrowser.Navigate(new Uri(String.Format("file:\{0}\mymap.html", curDir)));

浏览器打开,顶部有黄色警告:

"to help protect your security, your browser has restricted this file from showing active content .."

我点击它,允许被阻止的内容,然后我收到一条消息,说页面中的脚本有错误。我允许它继续,但浏览器仍然空白..这是为什么?

搜索答案后,我发现了这篇博文:

https://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version

首先对于黄色警告,只需在页面的 html 标签下添加此评论行:

<!-- saved from url=(0016)http://localhost -->

您可以在此处阅读更多相关信息:

https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/compatibility/ms537628(v=vs.85)

关于地图和脚本错误:

您似乎需要将 WebBrowser 的 IE 版本设置为边缘,以便能够呈现 HTML5。

将此行设置为 head 标签内的第一行:

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

经过这 2 次更改后,它将起作用