“此页面上的脚本中发生了错误”。尝试通过XAML API显示HTM文件时
这可能太具体了,但是每当我运行此代码时,我都会出现错误。
private void WebBrowser_Clicked(object sender, RoutedEventArgs e)
{
wb.Navigate("C:/Users/intern3/source/repos/MarketingProject/Samples/WPF/RESTToolkitTestApp/index.htm");
}
WB是XAML文件中WebBrowser元素的名称。
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=AgCKDO35_SFD68BDTuy_{my key}' async defer></script>
<script type='text/javascript'>
var map;
var coords = '<%=coords%>';
function GetMap() {
map = new Microsoft.Maps.Map('#myMap', {center: new Microsoft.Maps.Location(55, 0)});
//Create a pushpin.
var pushpin1 = new Microsoft.Maps.Pushpin(map.getCenter());
map.entities.push(pushpin1);
//Add mouse events to the pushpin.
Microsoft.Maps.Events.addHandler(pushpin1, 'click', function () { highlight('pushpinClick'); });
Microsoft.Maps.Events.addHandler(pushpin1, 'mouseover', function () { highlight('pushpinMouseover'), showinfo('address'); });
}
function highlight(id) {
//Highlight the mouse event div to indicate that the event has fired.
document.getElementById(id).style.background = 'LightGreen';
setTimeout(function () { document.getElementById(id).style.background = 'white'; }, 1000);
}
function showinfo(id)
{
document.getElementById(id).style.background = 'LightGreen';
setTimeout(function () { document.getElementById(id).style.background = 'white'; }, 1000);
document.getElementById(id).textContent = coords;
}
</script>
...
This might be a little too specific, but whenever I run this code, I get an error.
private void WebBrowser_Clicked(object sender, RoutedEventArgs e)
{
wb.Navigate("C:/Users/intern3/source/repos/MarketingProject/Samples/WPF/RESTToolkitTestApp/index.htm");
}
wb is the name of a WebBrowser element in a XAML file.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=AgCKDO35_SFD68BDTuy_{my key}' async defer></script>
<script type='text/javascript'>
var map;
var coords = '<%=coords%>';
function GetMap() {
map = new Microsoft.Maps.Map('#myMap', {center: new Microsoft.Maps.Location(55, 0)});
//Create a pushpin.
var pushpin1 = new Microsoft.Maps.Pushpin(map.getCenter());
map.entities.push(pushpin1);
//Add mouse events to the pushpin.
Microsoft.Maps.Events.addHandler(pushpin1, 'click', function () { highlight('pushpinClick'); });
Microsoft.Maps.Events.addHandler(pushpin1, 'mouseover', function () { highlight('pushpinMouseover'), showinfo('address'); });
}
function highlight(id) {
//Highlight the mouse event div to indicate that the event has fired.
document.getElementById(id).style.background = 'LightGreen';
setTimeout(function () { document.getElementById(id).style.background = 'white'; }, 1000);
}
function showinfo(id)
{
document.getElementById(id).style.background = 'LightGreen';
setTimeout(function () { document.getElementById(id).style.background = 'white'; }, 1000);
document.getElementById(id).textContent = coords;
}
</script>
...
There are other div elements that display, but it's just the map that doesn't.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是旧的WPF WebBrowser控件,请确保添加
&lt; meta charset =“ utf-8” http-equiv =“ x-ua兼容” content =“ ie = gede gent” /&gt; < /code >到您页面的头部。如果不这样做,它将使用bing Maps不支持的IE6渲染。在这里记录了这一点: https://learn.microsoft.com/en-us/bingmaps/v8-web-control/articles/cross-platform-bing-maps-maps-maps-v8-apps#using-bing-bing-maps-v8-in-in-winform - 和wpf-apps
If you are using the old WPF WebBrowser control be sure to add
<meta charset="utf-8" http-equiv="X-UA-Compatible" content="IE=edge" />
to the head of your page. If you don't it will use IE6 rendering which isn't supported by Bing Maps. This is documented here: https://learn.microsoft.com/en-us/bingmaps/v8-web-control/articles/cross-platform-bing-maps-v8-apps#using-bing-maps-v8-in-winform-and-wpf-apps