当用户点击Android后退按钮时,导航2个屏幕? (PhoneGap的)

时间:2015-04-21 10:44:40

标签: javascript jquery html5 cordova

当用户点击Android的后退按钮时,如何让应用导航2个屏幕?

以下代码:

if(document.getElementById("HomeCtrl") != undefined){
        navigator.notification.confirm(messages[appLanguage].exitFromApp, function(buttonIndex){
            if(buttonIndex == 1){
                navigator.app.exitApp();
            };
        }, messages[appLanguage].appName, ["Ok","Cancel"])
        this.preventDefault();
    } else if(document.getElementById("BookCabController") != undefined){
        angular.element(document.getElementById("BookCabController")).scope().navigationService.back();
    } else if(document.getElementById("ReviewAndConfirmController") != undefined){
        angular.element(document.getElementById("ReviewAndConfirmController")).scope().navigationService.back();            
    }
}

1 个答案:

答案 0 :(得分:0)

这应该适合你。

document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
        document.addEventListener("backbutton", onBackKeyDown, false );
}

function onBackKeyDown() {
    history.go(-2);
}