Javascript Cordova应用程序位于服务器上(不在设备上)-不触发事件
我正在为Android 4.4设备编写cordova(版本6)应用程序。在这里,我试图捕捉按钮按下事件,例如音量下降按钮。不幸的是,我需要在服务器上托管应用程序。这意味着所有html、css和js文件都是远程加载的。而应用程序本身的Javascript Cordova应用程序位于服务器上(不在设备上)-不触发事件,javascript,java,android,cordova,event-handling,Javascript,Java,Android,Cordova,Event Handling,我正在为Android 4.4设备编写cordova(版本6)应用程序。在这里,我试图捕捉按钮按下事件,例如音量下降按钮。不幸的是,我需要在服务器上托管应用程序。这意味着所有html、css和js文件都是远程加载的。而应用程序本身的index.html仅包含: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="Content-Sec
index.html
仅包含:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>My App</title>
<script type="text/javascript">
function init() {
window.location.href="http://example.com:3000/myapp";
}
</script>
</head>
<body id="body" onload="init();">
</body>
</html>
有人能告诉我,为什么这段代码不再有效,并帮我解决这个问题吗?像这样试试
//Gets called from the body-tag of the html-site - works!
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
//This works!
console.log("onDeviceReady");
}
document.addEventListener("backbutton", onBackKeyDown, false);
document.addEventListener("volumeupbutton", onVolumeUpKeyDown, false);
document.addEventListener("menubutton", onMenuKeyDown, false);
function onMenuKeyDown(event) {
console.log("menu pressed");
}
function onBackKeyDown(event) {
console.log("back pressed");
}
function onVolumeUpKeyDown() {
console.log("Volume up pressed");
}
//Gets called from the body-tag of the html-site - works!
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
//This works!
console.log("onDeviceReady");
}
document.addEventListener("backbutton", onBackKeyDown, false);
document.addEventListener("volumeupbutton", onVolumeUpKeyDown, false);
document.addEventListener("menubutton", onMenuKeyDown, false);
function onMenuKeyDown(event) {
console.log("menu pressed");
}
function onBackKeyDown(event) {
console.log("back pressed");
}
function onVolumeUpKeyDown() {
console.log("Volume up pressed");
}