我正在使用phonegap开发移动应用程序,但我在处理后退按钮事件时遇到问题。我的代码是,
我的index.js
中已准备好设备var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
parsePlugin.initialize("xxxxxxx", "xxxxxxx", function(){
//nothing required to do
}, function(e){
alert('Unable to Initialize Parse!');
});
parsePlugin.getInstallationId(function(id) {
window.localStorage.setItem("deviceToken", id);
}, function(e) {
alert('Unable to get DeviceToken!');
});
app.receivedEvent('deviceready');
window.location = "main.html"
},
// Update DOM on a Received Event
receivedEvent: function(id) {
}
};
app.initialize();
我的index.js将我重定向到main.html页面,我有这段代码,
<script type="text/javascript">
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(e) {
alert('back button triggered');
console.log(e);
e.preventDefault();
return false;
}
</script>
请指导我,我的错误在哪里,为什么我没有收到后退活动。
答案 0 :(得分:0)
首先听取此事件:
document.addEventListener("deviceready", onDeviceReady, false);
看起来像这样:
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady{
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(e) {
alert('back button triggered');
console.log(e);
e.preventDefault();
return false;
}
}
</script>