Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows应用商店应用程序-WinJS:0x800a1391-JavaScript运行时错误:';视窗';是未定义的_Javascript_Html_Windows Store Apps_Winjs - Fatal编程技术网

Windows应用商店应用程序-WinJS:0x800a1391-JavaScript运行时错误:';视窗';是未定义的

Windows应用商店应用程序-WinJS:0x800a1391-JavaScript运行时错误:';视窗';是未定义的,javascript,html,windows-store-apps,winjs,Javascript,Html,Windows Store Apps,Winjs,我正在尝试将Google地图加载到Windows应用商店应用程序中。但是,本机Windows RT函数存在问题:Windows.UI.Popups.MessageDialog。我猜Windows名称空间超出了范围,但我现在不知道如何将此函数放入一个可以访问Windows名称空间的范围。感谢您的帮助 编辑:我越想这个问题,就越觉得它与我正在加载map.html作为iFrame的源代码这一事实有关。因此map.html的上下文是一个iFrame,而不是一个Windows应用商店应用程序页面。我猜Wi

我正在尝试将Google地图加载到Windows应用商店应用程序中。但是,本机Windows RT函数存在问题:Windows.UI.Popups.MessageDialog。我猜Windows名称空间超出了范围,但我现在不知道如何将此函数放入一个可以访问Windows名称空间的范围。感谢您的帮助

编辑:我越想这个问题,就越觉得它与我正在加载map.html作为iFrame的源代码这一事实有关。因此map.html的上下文是一个iFrame,而不是一个Windows应用商店应用程序页面。我猜Windows命名空间在iFrame中不可用

从home.html:

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

在web分区中执行的代码—您的URL显示该代码所在的位置—无法访问WinRT组件。您需要使用postMessage等在两个安全上下文之间进行通信。

来自Map.js:

        function locationFail() {
            //Can't do this due the the iFrame container
            //var md = new Windows.UI.Popups.MessageDialog("Could not find you!", "").showAsync;
            window.parent.postMessage("Could not find you!", "*");
        }
从Home.js:

(function () {
"use strict";

WinJS.UI.Pages.define("/pages/home/home.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) {

        window.addEventListener("message", messageReceived, false);

        function messageReceived(e) {
            if (e.origin === "ms-appx-web://76ad865e-25cf-485c-bc77-e18186bfd7ee") {
                var md = new Windows.UI.Popups.MessageDialog(e.data, "");
                md.showAsync();
            }
        };
    }
});
})();

我从这个博客得到了解决方案:

Dominic-非常感谢。postMessage是关键。我会投票支持你,但我没有足够的分数。我使用了来自dZone博客的代码来找到解决方案:
        function locationFail() {
            //Can't do this due the the iFrame container
            //var md = new Windows.UI.Popups.MessageDialog("Could not find you!", "").showAsync;
            window.parent.postMessage("Could not find you!", "*");
        }
(function () {
"use strict";

WinJS.UI.Pages.define("/pages/home/home.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) {

        window.addEventListener("message", messageReceived, false);

        function messageReceived(e) {
            if (e.origin === "ms-appx-web://76ad865e-25cf-485c-bc77-e18186bfd7ee") {
                var md = new Windows.UI.Popups.MessageDialog(e.data, "");
                md.showAsync();
            }
        };
    }
});
})();