Android Phonegap中的电话BackKey功能

时间:2013-09-05 10:02:43

标签: android cordova

请帮帮我......

我正在使用phonegap-1.1.0v。在我的应用程序中,我有多个HTML文件。每个文件都是一个页面     每个页面都包含每个HTML页面顶部的主页按钮。

when i  moved from Homepage -- > screen B --> Again Homepage --> screen c

when i pressed Back key on Screen c it goes back to Homepage but when i press the Backkey again it goes to Screen B and the Homepage. 

 For MY solution i requires when i press the Back key from home screen it always need to Flash screen page (or) it should get exit from the application.

提前致谢.............:)

3 个答案:

答案 0 :(得分:0)

//Deviceready function
document.addEventListener('deviceready', function() {

                          document.addEventListener("backbutton", go_back, false);

                          }, false);


function go_back(){
    // Put your code when back key is press
    // U can use window.location="home.html" to change page or something else
    // If u want to exit then use "device.exitApp();"
    }

答案 1 :(得分:0)

以下是您的工作方式

document.addEventListener("backbutton", function(e){
    if($.mobile.activePage.is('#homepage')){
        e.preventDefault();
        navigator.app.exitApp();
    }
    else {
        navigator.app.backHistory()
    }
}, false);

答案 2 :(得分:0)

为此,您必须使用全局布尔变量,当您到达家中时,将其设为true并在每次按下后退按钮时检查此变量:

if (device.platform == 'android') 
{
    document.addEventListener("backbutton", onBackKeyDown, false); 

    function onBackKeyDown(e) 
    {
        if(isHome)
        {
            navigator.app.exitApp();
        }
        else
        {
            navigator.app.backHistory();
            //What you want when its not home page
        }
    }
}