“此页面上的脚本中发生了错误”。尝试通过XAML API显示HTM文件时

发布于 2025-02-13 18:13:45 字数 2018 浏览 1 评论 0原文

这可能太具体了,但是每当我运行此代码时,我都会出现错误。

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.
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作业与我同在 2025-02-20 18:13:45

如果您使用的是旧的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-b​​ing-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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文