简体   繁体   中英

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. The following does not work for Index.html, I've only added a single button with an onclick event,

<!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

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 . 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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