繁体   English   中英

用于Apache Cordova的JavaScript代码在模拟器Ripple上运行,但不在Live Windows Phone设备中运行(L 535)

[英]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>

Ripple(Android)的屏幕截图:效果很好!


Windows Phone(Lumia 535)的屏幕截图

原因是因为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.

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