Reputation: 11
I wrote a just a test javascript code in index.js , it's an ordinary alert(), when ever I test in on ripple as android it works fine , when I test it on my Windows Phone its showing
Unhandled exception at line 16, column 13 in
ms-appx://io.cordova.myapp16ff10/www/scripts/index.js
0x800a1391 - JavaScript runtime error: 'alert' is undefined
index.js
(function () {
"use strict";
document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener('resume', onResume.bind(this), false);
document.getElementById("btnTakePhoto").onclick = function () {
alert("button working fine!");
};
// TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
};
function onPause() {
// TODO: This application has been suspended. Save application state here.
};
function onResume() {
// TODO: This application has been reactivated. Restore application state here.
};
} )();
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<title>CameraDemoApp</title>
<!-- CameraDemoApp references -->
<link href="css/index.css" rel="stylesheet" />
</head>
<body>
<h2>Hello, world!</h2>
<input id="btnTakePhoto" type="button" value="Take a Photo" />
<p id="lastPhoto"></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>
</body>
</html>
Screenshot for Ripple (Android): it works fine!
Screenshot for Windows Phone (Lumia 535)
Upvotes: 1
Views: 505
Reputation: 3217
The reason is because there is no built-in support for alert
in Windows Phone 7 and 8. Use PhoneGap's Notification API instead, and have something like this:
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
window.alert = window.alert || navigator.notification.alert;
alert('button working fine!');
}
Upvotes: 2