简体   繁体   English

Visual Studio 2015 RC Cordova应用程序(Windows Phone Universal,“警报”未定义)

[英]Visual Studio 2015 RC Cordova App (Windows Phone Universal, “alert” undefined)

I have a basic Cordova app, literally the default template from Visual Studio 2015 RC. 我有一个基本的Cordova应用程序,实际上是Visual Studio 2015 RC的默认模板。 The following does not work for Index.html, I've only added a single button with an onclick event, 以下内容不适用于Index.html,我只添加了一个带有onclick事件的按钮,

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>OMFG</title>

    <!-- OMFG references -->
    <link href="css/index.css" rel="stylesheet" />
</head>
<body>
    <p>Hello, your application is ready!</p>

    <!-- Cordova reference, this is added to your app when it's built. -->
    <script src="cordova.js"></script>
    <script src="scripts/platformOverrides.js"></script>

    <script src="scripts/index.js"></script>

    <button onclick="alert('foobar!');">Do Stuff!</button>
</body>
</html>

I get 我懂了

0x800a1391 - JavaScript runtime error: 'alert' is undefined 0x800a1391-JavaScript运行时错误:“警报”未定义

Any idea what's happening? 知道发生了什么事吗?

I had the same problem at first using VS 2015. alert doesn't work on mobile phones -- you'll just need to replace it with notification.alert . 我在第一次使用VS 2015年同样的问题, alert在手机上不工作-你只需要更换它notification.alert Don't forget to add the notification plugin. 不要忘记添加通知插件。

Here is an example that I used and it works perfectly: 这是我使用的一个示例,它可以完美运行:

navigator.notification.alert(
   'Authentification réussi !', // message
   'Authentification réussi !', // title
   'Authentification'           // buttonName
);  

You can't just found out you have to use this, 您不能仅仅发现自己必须使用它,

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

My bad! 我的错!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM