Nick
Nick

Reputation: 1025

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?

Upvotes: 2

Views: 1515

Answers (3)

Hela Fodha
Hela Fodha

Reputation: 44

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
);  

Upvotes: 3

Hela Fodha
Hela Fodha

Reputation: 44

navigator.notification.alert( 'Authentification failed !', // message 'Authentification failed !', // title 'Authentification' // buttonName );

Upvotes: 0

Nick
Nick

Reputation: 1025

You can't just found out you have to use this,

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

My bad!

Upvotes: 2

Related Questions