[Vuejs]-Cordova android backbutton confirmation message

0👍

It doesn’t matter which js you are using. if you want to implement the above requirement you need to install the following plugin.

cordova plugin add cordova-plugin-dialogs

and sample code as follows

document.addEventListener("deviceready", onDeviceReady, false);
 function onDeviceReady(){
         document.addEventListener("backbutton", function(e){
        navigator.notification.confirm("Are you sure you want to exit the application?",fnLogout,"Warning","Ok,Cancel"); // u can change the button names in the place of ok,cancel.
    }, false); 
}

function fnLogout(button) {
    if(button == 1) {
        navigator.app.exitApp(); //exit from the if presses "ok"
    } else {
        return; //No action if presses "cancel"
    }                     
 }

Leave a comment