[英]Page Navigation on Windows Phone 8 using HTML/JavaScript/Apache Cordova
[英]javascript code for apache Cordova working on simulator Ripple but not in Live windows phone Device (L 535)
我在index.js中编写了一个测试javascript代码,这是一个普通的alert(),每当我在rip上测试为android时,它都能正常工作,当我在Windows Phone上测试它时
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>
原因是因为Windows Phone 7和8中没有内置的alert
支持。请改用PhoneGap的Notification API ,并进行如下操作:
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
window.alert = window.alert || navigator.notification.alert;
alert('button working fine!');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.