简体   繁体   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)

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 我在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 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 的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! Ripple(Android)的屏幕截图:效果很好!


Screenshot for Windows Phone (Lumia 535) Windows Phone(Lumia 535)的屏幕截图

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

相关问题 Windows Phone 8上使用HTML / JavaScript / Apache Cordova的页面导航 - Page Navigation on Windows Phone 8 using HTML/JavaScript/Apache Cordova 为什么将JavaScript称为“ alert();” 功能为Apache Cordova开发时,Windows Phone中的应用程序崩溃了吗? - Why does calling the JavaScript 'alert();' function crash the app in Windows Phone when developing for Apache Cordova? a href onclick在Windows Phone Cordova应用中不起作用 - a href onclick not working in windows phone cordova app 外部JavaScript在模拟器中工作,但不在ios设备中工作 - External javascript working in simulator but not in ios device 最新的涟漪图不适用于phonegap(与Cordova兼容) - Latest Ripple not working with phonegap (works with Cordova) 科尔多瓦的Windows Phone问题8 - Cordova problems with windows phone 8 JavaScript在Windows Mobile和Windows Phone上不起作用 - JavaScript is not working on Windows Mobile and Windows Phone 科尔多瓦应用程序到WP8 window.location无法正常工作的Windows Phone - cordova app to wp8 window.location not working windows phone innerHTML在Cordova Android模拟器中不起作用 - innerHTML not working in Cordova Android simulator Windows Phone 8 Web浏览器Javascript不起作用 - Windows Phone 8 Web Browser Javascript not Working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM