我正在使用Jquery Mobile / Phonegap开发Android应用程序 . 我有以下代码来控制手机的后退按钮:
document.addEventListener("backbutton", backKeyDown, true);
function backKeyDown() {
// Call my back key code here.
$.mobile.changePage("#homepage", "slideup");
}
这一切都很好,但我希望应用程序只在主页上按下后退按钮时关闭,这可能吗?
4 回答
Update: this has stopped working with a latest Phonegap update (supposedly). Feel free to offer a working solution if you know it.
我是这样做的:
有关详细信息,请在此处找到相关文档以及完整示例:http://docs.phonegap.com/en/2.0.0/cordova_events_events.md.html#backbutton
谢谢spader .
您需要跟踪主页的显示时间 . 如果您知道自己正在主页上致电:
如果您不想使用jQuery Mobile,请在@Spadar上将
$.mobile.activePage.is('#homepage')
更改为document.getElementById('#homepage')
关闭答案,如下面的代码所示:通过这种方式,不需要为此目的下载Jquery Mobile乱码 . Also, activePage is deprecated as of JQuery mobile 1.4.0并将从1.5.0中删除 . (Use the getActivePage() method from the pagecontainer widget instead)