在metro应用中,“alert”的替代方案是什么? [英] What is the alternative to `alert` in metro apps?

查看:161
本文介绍了在metro应用中,“alert”的替代方案是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 8 vs 2012上创建了我的第一个应用程序,它运行良好。但当我试图用这样的JavaScript来说helloworld时:

I created my first app on Windows 8 vs 2012 and it runs and works fine. But when I try to say "helloworld" from JavaScript like this:

alert("Hello World");

我收到错误消息:

Unhandled exception at line 21,
 column 13 in ms-appx://1af489cf-bac6-419b-8542-fdc18bdd2747/default.html

0x800a1391 - JavaScript runtime error: 'alert' is undefined

如果警报,可以选择什么已过时?

推荐答案

您应该使用 Windows.UI.Popups。 MessageDialog

(new Windows.UI.Popups.MessageDialog("Content", "Title")).showAsync().done();

但是,你应该知道:


  • 这是阻止,如熟悉的提醒

  • 因为它没有阻止你可能会尝试向他们显示多个消息框;这是不允许的。

  • This is not blocking like the familiar alert
  • Because it's not blocking you may try to show them multiple messages boxes; this isn't allow.

我回答了另一个问题此处。以下是允许您呼叫提醒并在飞行中有多条消息的代码:

I answered another question like this here. Here's the code to allow you to call alert, and have multiple messages in flight:

(function () {
    var alertsToShow = [];
    var dialogVisible = false;

    function showPendingAlerts() {
        if (dialogVisible || !alertsToShow.length) {
            return;
        }

        dialogVisible = true;
        (new Windows.UI.Popups.MessageDialog(alertsToShow.shift())).showAsync().done(function () {
            dialogVisible = false;
            showPendingAlerts();
        })
    }
    window.alert = function (message) {
        if (window.console && window.console.log) {
            window.console.log(message);
        }

        alertsToShow.push(message);
        showPendingAlerts();
    }
})();

这篇关于在metro应用中,“alert”的替代方案是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆