Javascript Cordova Devicerady没有开火
我有一个多页应用程序,我正在尝试在camera.html文件中使用“deviceready”fire。我正在链接index.js文件并将cordova.js添加到camera.html文件中。下面是我的index.js文件中的代码Javascript Cordova Devicerady没有开火,javascript,cordova,cordova-plugin-camera,Javascript,Cordova,Cordova Plugin Camera,我有一个多页应用程序,我正在尝试在camera.html文件中使用“deviceready”fire。我正在链接index.js文件并将cordova.js添加到camera.html文件中。下面是我的index.js文件中的代码 let app = { initialize: function() { this.bindEvents(); console.log("app has been initialized") }, b
let app = {
initialize: function() {
this.bindEvents();
console.log("app has been initialized")
},
bindEvents: function(){
document.addEventListener('deviceready', this.onDeviceReady, false);
console.log("events have been bound")
},
onDeviceReady: function() {
console.log("Hitting device ready");
let cameraApp= {
init: function(){
$('#btn').click(cameraApp.getalbum);
console.log("this button works");
$('#camera').click(cameraApp.takephoto);
},
takephoto: function(){
let cameraOptions = {
quality: 80,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
};
navigator.camera.getPicture(cameraApp.onSuccess, cameraApp.onFail, cameraOptions);
console.log("ClickedCameraButton");
},
getalbum: function(){
let cameraOptions = {
quality: 80,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
};
navigator.camera.getPicture(cameraApp.onSuccess, cameraApp.onFail, cameraOptions);
console.log("ClickedCameraAlbumbutton");
},
onSuccess: function(imageURI){
document.getElementById('photo').src = imageURI;
},
onFail: function(msg){
document.getElementById('msg').textContent = msg;
}
};
cameraApp.init();
}
};
var pageTitle = document.title;
console.log("pageTitle:" + pageTitle);
$(document).ready(function() {
switch(pageTitle) {
case "Home":
let url = 'https://jyoti.thetoolboxapp.co/views/login.html'
let delay = 3000;
console.log("Loading home");
setTimeout(function() {window.location.href = url;}, delay);
break;
case "Login":
console.log("login reading");
$("#login").click(function() {
let delay = 1000;
let url = 'https://jyoti.thetoolboxapp.co/views/camera.html';
setTimeout(function() {
window.location.href = url;
}, delay);
console.log("Clicked button.");
});
break;
case "Camera":
app.initialize();
break;
default:
console.log("this did not work");
break;
}
});
该应用程序可以访问console.log(“事件已绑定”),但无法访问onDeviceReady函数。我的印象是“deviceready”只在index.html页面中启动,但肯定有一个解决方案