最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Hardware Back Button in Cordova Framework7 App - Stack Overflow

programmeradmin2浏览0评论

I am developing a tutorial app using the Cordova Framework7 framework. When I build the APK and test it on my mobile device, I encounter an issue where clicking the back button closes the app. I would like to modify this behavior so that the back button should navigate back to the previous page, unless the current page is the main page (in which case, the app should exit). Could you please help me with the code to implement this functionality?

var app = new Framework7({
    id: 'io.framework7.testapp',
    el: '#app',
    cache: false, /* disable caching */
    theme: theme,
    pushState : true,
    routes: routes,
    popup: {
        closeOnEscape: true,
    },
    sheet: {
        closeOnEscape: true,
    },
    popover: {
        closeOnEscape: true,
    },
    actions: {
        closeOnEscape: true,
    },
    vi: {
        placementId: 'pltd4o7ibb9rc653x14',
    },
    methods:
    {
        onBackKeyDown: function() 
        {
            if (app.views.main.router.url == '/') {
                app.dialog.confirm('Are you sure you want to exit?', 'Exit app', function() {
                    navigator.app.exitApp();
                },
                function() {
                });
            } else {
                mainView.router.back();
            }
        }
    }
});

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

I had tried this code but its not working. I want to correct my code so that it works

发布评论

评论列表(0)

  1. 暂无评论