加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

Windows应用商店应用 – WinJS:0x800a1391 – JavaScript运行时

发布时间:2020-12-14 03:58:47 所属栏目:Windows 来源:网络整理
导读:我正在尝试将Google地图加载到 Windows应用商店应用中.但是,本机Windows RT函数出现问题:Windows.UI.Popups.MessageDialog.我猜测Windows命名空间超出了范围,但我现在无法弄清楚是否将此函数放入可使Windows命名空间可访问的范围内.任何帮助表示赞赏. 编辑
我正在尝试将Google地图加载到 Windows应用商店应用中.但是,本机Windows RT函数出现问题:Windows.UI.Popups.MessageDialog.我猜测Windows命名空间超出了范围,但我现在无法弄清楚是否将此函数放入可使Windows命名空间可访问的范围内.任何帮助表示赞赏.

编辑:我越想到这一点,我认为它与我加载map.html作为iFrame的源这一事实有关.因此,map.html的上下文是iFrame,而不是Windows应用商店应用页面.我想在iFrame中无法使用Windows命名空间?

来自home.html:

<iframe id="getLocationFrame" src="ms-appx-web:///pages/map/map.html" style="width:600px; height:600px;"></iframe>

例外:

SCRIPT5009:ms-appx-web中第50行第17行的未处理异常://76ad865e-25cf-485c-bc77-e18186bfd7ee/pages/map/map.js
0x800a1391 – JavaScript运行时错误:’Windows’未定义
文件:map.js,行:50,列:17

map.html:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="//Microsoft.WinJS.1.0/js/base.js"></script>
    <script type="text/javascript" src="//Microsoft.WinJS.1.0/js/ui.js"></script>

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?  sensor=false"></script>        
    <script type="text/javascript" src="map.js"></script>

    <link href="/pages/map/css/map.css" rel="stylesheet" />
    <link href="//Microsoft.WinJS.1.0/css/ui-light.css" rel="stylesheet" />
</head>
<body>
    <p>Click to get your location.</p>
    <button id="getLocation">Get Location</button><br/>
    <div id="mapcontainer"></div><br />
    <small>
        <a id="anchorLargerMap" href="" style="color:#0000FF;text-align:left" target="_blank">View Larger Map</a>
    </small>
</body>
</html>

map.js:

(function () {
"use strict";

WinJS.UI.Pages.define("/pages/map/map.html",{

    // This function is called whenever a user navigates to this page. It
    // populates the page elements with the app's data.
    ready: function (element,options) {
        //Button "getLocation" event handler
        function getLocationClickHandler(eventInfo) {
            var myOptions = {
                zoom: 13,mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            var mapcontainer = document.getElementById("mapcontainer");
            var map = new google.maps.Map(mapcontainer,myOptions);

            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(locationSuccess,locationFail);
            }
        }

        var namespacePublicMembers = {
            locationSucessFunction: locationSuccess,locationFailFunction: locationFail,getLocationClickEventHandler: getLocationClickHandler
        };

        WinJS.Namespace.define("mapPage",namespacePublicMembers);
        var getLocationButton = document.getElementById("getLocation");
        getLocationButton.addEventListener("click",getLocationClickHandler,false);

        function locationSuccess(position) {
            var initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
            map.setCenter(initialLocation);
            var marker = new google.maps.Marker({
                position: initialLocation,map: map,title: "You are here."
            });

            var latitude = position.coords.latitude;
            var longitude = position.coords.longitude;
            var url = "http://maps.google.com/maps?q=" + latitude + "," + longitude + "&zoom=13&markers=" + latitude + "," + longitude;
            $("#anchorLargerMap").attr('href',url);
        }

        function locationFail() {
            var md = new Windows.UI.Popups.MessageDialog("Could not find you!","").showAsync;  -- ********* THIS LINE THROWS EXCEPTION *********
        }
    }
});
})();

解决方法

在Web分区中执行的代码 – 您的URL表示此代码所在的代码 – 无法访问WinRT组件.您需要使用postMessage等在两个安全上下文之间进行通信.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读