gpt4 book ai didi

apache Cordova 的 javascript 代码在模拟器 Ripple 上工作但不在 Live windows phone 设备 (L 535)

转载 作者:行者123 更新时间:2023-11-30 16:31:43 25 4
gpt4 key购买 nike

我在 index.js 中只写了一个测试 javascript 代码,它是一个普通的 alert(),当我在 ripple 上测试时它工作正常,当我在我的 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>

Screenshot for Ripple (Android): it works fine!


Screenshot for 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!');
}

关于apache Cordova 的 javascript 代码在模拟器 Ripple 上工作但不在 Live windows phone 设备 (L 535),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33226629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com