Android 带有HTML 5的deviceready事件上的PhoneGap错误
我有一个可以想象得到的最简单的PhoneGap应用程序 我所要做的就是在DeviceRady事件上显示一条警告消息 HTML代码Android 带有HTML 5的deviceready事件上的PhoneGap错误,android,html,cordova,simulator,Android,Html,Cordova,Simulator,我有一个可以想象得到的最简单的PhoneGap应用程序 我所要做的就是在DeviceRady事件上显示一条警告消息 HTML代码 <!DOCTYPE HTML> <html> <head> <title>PhoneGap</title> <script type="text/javascript" charset="utf-8" src="phonegap.js"></script> &l
<!DOCTYPE HTML>
<html>
<head>
<title>PhoneGap</title>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8" src="common.js"></script>
</head>
<body>
<div data-role="page" id="index-page">
<h1>Hello World!</h1>
</body>
</html>
var isPhoneGapReady = false;
function init() {
document.addEventListener("deviceready",
onDeviceReady, false);
// Older versions of Blackberry < 5.0 don't support
// PhoneGap's custom events, so instead we need to
// perform an interval check every 500 milliseconds
// to see if PhoneGap is ready. Once done, the
// interval will be cleared and normal processing
// can begin
var intervalID = window.setInterval(function() {
if (PhoneGap.available) {
onDeviceReady();
}
}, 500);
}
function onDeviceReady() {
window.clearInterval(intervalID);
// set to true
isPhoneGapReady = true;
alert("The device is now ready");
}
// Set an onload handler to call the init function
window.onload = init;
如果有人能指出需要做什么来纠正错误,我将不胜感激
谢谢,我认为您遇到的问题是,
intervalID
的作用域没有到达onDeviceReady()
函数。您需要在init()函数中创建该函数,如下所示-
var isPhoneGapReady = false;
function init() {
document.addEventListener("deviceready", onDeviceReady, false);
// Older versions of Blackberry < 5.0 don't support
// PhoneGap's custom events, so instead we need to
// perform an interval check every 500 milliseconds
// to see if PhoneGap is ready. Once done, the
// interval will be cleared and normal processing
// can begin
var intervalID = window.setInterval(function() {
if (PhoneGap.available) {
onDeviceReady();
}
}, 500);
// REMOVE THIS
// }
function onDeviceReady() {
window.clearInterval(intervalID);
// set to true
isPhoneGapReady = true;
alert("The device is now ready");
}
// PUT THIS HERE
}
// Set an onload handler to call the init function
window.onload = init;
var isPhoneGapReady=false;
函数init(){
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
//黑莓<5.0的旧版本不支持
//PhoneGap的自定义事件,因此我们需要
//每500毫秒执行一次间隔检查
//查看PhoneGap是否准备就绪。完成后
//间隔将被清除并正常处理
//可以开始
var intervalID=window.setInterval(函数(){
如果(PhoneGap.available){
ondevicerady();
}
}, 500);
//去掉这个
// }
函数ondevicerady(){
窗口。clearInterval(intervalID);
//设置为真
isPhoneGapReady=true;
警报(“设备现在已准备就绪”);
}
//把这个放在这里
}
//设置一个onload处理程序来调用init函数
window.onload=init;
DeviceQady不能在window.onLoad之前发生。
var isPhoneGapReady = false;
function init() {
document.addEventListener("deviceready", onDeviceReady, false);
// Older versions of Blackberry < 5.0 don't support
// PhoneGap's custom events, so instead we need to
// perform an interval check every 500 milliseconds
// to see if PhoneGap is ready. Once done, the
// interval will be cleared and normal processing
// can begin
var intervalID = window.setInterval(function() {
if (PhoneGap.available) {
onDeviceReady();
}
}, 500);
// REMOVE THIS
// }
function onDeviceReady() {
window.clearInterval(intervalID);
// set to true
isPhoneGapReady = true;
alert("The device is now ready");
}
// PUT THIS HERE
}
// Set an onload handler to call the init function
window.onload = init;