好吧,根据这个Link PhoneGap 有一个 API 来处理后键事件。所以你可以在你的java脚本代码中使用一个私有字段,它将一个标志设置为可见或不可见(布尔值)并相应地处理回键事件。
伪代码看起来像这样:
<script type="text/javascript" charset="utf-8">
var visible = false;
// Call onDeviceReady when Cordova is loaded.
//
// At this point, the document has loaded but cordova-2.6.0.js has not.
// When Cordova is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onBackKeyDown() {
if(visible) {
//wait
} else {
//finish
}
}
function showDialog(){
visible = true;
// your code
}
// Cordova is loaded and it is now safe to make calls Cordova methods
//
function onDeviceReady() {
document.addEventListener("offline", onOffline, false);
document.addEventListener("backbutton", onBackKeyDown, false);
}
// Handle the offline event
//
function onOffline() {
}
</script>