0

请帮我解决这个问题......

我正在使用 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.

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

4

3 回答 3

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();"
    }
于 2013-09-05T10:08:44.700 回答
0

这是你的做法

document.addEventListener("backbutton", function(e){
    if($.mobile.activePage.is('#homepage')){
        e.preventDefault();
        navigator.app.exitApp();
    }
    else {
        navigator.app.backHistory()
    }
}, false);
于 2013-09-05T10:09:26.030 回答
0

为此,您必须获取一个全局布尔变量,当您回到家时,请使其为真,并在每次按下后退按钮时检查此变量,例如:

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
        }
    }
}
于 2013-09-05T10:11:28.540 回答