I've been working on a WebApp project recently, encountered the problem of exit, in order to improve the user experience, the intention to press the return key after the user needs to confirm again to quit, search on the internet, found that a lot of the need for a variety of plug-ins, for such a simple function, if the introduction of a plug-in is obviously not worth it, Finally kung fu, I still found a very good code, recorded.
Document.addeventlistener ("Deviceready", Ondeviceready, false);
function Ondeviceready () {
Registering the Fallback button event listener
Document.addeventlistener ("Backbutton", Onbackkeydown, false);
}
Return key
function Onbackkeydown () {
Navigator.notification.confirm (
' Press OK to exit the program! ',//message
Onconfirm,//callback to invoke with index of button pressed
' Are you sure you want to quit the program? ',//title
' OK, Cancel '//Buttonlabels
);
}
function onconfirm (button) {
if (button==1) navigator.app.exitApp (); Select OK to perform exit
}
If you are in need of such a function, quickly take the past to use it!