Cordova jquery mobile backbutton退出特定页面的应用程序
我环顾四周,似乎无法将backbutton绑定到Phonegap/JQM中Android手机的特定页面 我试图只允许backbutton触发Cordova jquery mobile backbutton退出特定页面的应用程序,cordova,jquery-mobile,Cordova,Jquery Mobile,我环顾四周,似乎无法将backbutton绑定到Phonegap/JQM中Android手机的特定页面 我试图只允许backbutton触发导航。通知。确认以提示在一个特定页面注销。但它要么不提示,要么每一页都提示 下面这个不会触发 $(document).on( 'pageinit','homepage',function onLoad(){ document.addEventListener('deviceready', deviceReady, false)
导航。通知。确认以提示在一个特定页面注销。但它要么不提示,要么每一页都提示
下面这个不会触发
$(document).on( 'pageinit','homepage',function onLoad(){
document.addEventListener('deviceready', deviceReady, false);
}
function deviceReady() {
document.addEventListener('backbutton', backButtonCallback, false);
}
function backButtonCallback() {
navigator.notification.confirm('Do you want to exit the app? If not, use the top left button to go to Previous Page',confirmCallback);
}
function confirmCallback(buttonIndex) {
if(buttonIndex == 1) {
navigator.app.exitApp();
return true;
}
else {
return false;
}
})
这也不会触发
function onLoad(){
document.addEventListener('deviceready', deviceReady, false);
}
function deviceReady() {
document.addEventListener('backbutton','#homepage' backButtonCallback, false);
}
function backButtonCallback() {
navigator.notification.confirm('Do you want to exit the app? If not, use the top left button to go to Previous Page',confirmCallback);
}
function confirmCallback(buttonIndex) {
if(buttonIndex == 1) {
navigator.app.exitApp();
return true;
}
else {
return false;
}
}
如果您使用的是Jquery Mobile 1.4.5 getActivePage(),那么就很方便了。$。jqm1.4.0中不推荐使用mobile.activePage(请参阅自1.4.0 beta版以来的更改)
只有当activePage id为homepage时,此代码才会退出应用程序
告诉我代码是否适合您。谢谢,我现在就试试,但我使用的是1.4.4 tho。我将下载1.4.5并试一试!它起作用了!!非常感谢!!我想投你一票,但我的分数不够yet@John你使用过1.4.4吗?自从1.4.0 beta版以来就出现了弃用,所以我相信该方法也适用于1.4.4。我查阅了1.4.4文档,搜索了activePage函数,但没有找到任何相关内容。但是它在1.4.5文档中,所以我只是将1.4.4切换到1.4.5。
//handle Back button
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
console.log('Device ready - register onBackKeyDown()');
}
document.addEventListener("deviceready", onDeviceReady, false);
function onBackKeyDown() {
var active_page = $( ":mobile-pagecontainer" ).pagecontainer( "getActivePage" );
var id =active_page.page().attr('id');
if (id==='homepage') {
if (confirm('Do you want to exit the app? If not, use the top left button to go to Previous Page?')==true){
navigator.app.exitApp();
}
}
else{
navigator.app.backHistory();
}
}
//**