-
-
Save WuglyakBolgoink/5fa8f5da4daf09014f7d18b1a6e1f745 to your computer and use it in GitHub Desktop.
Cordova/PhoneGap exit app after twice press back button with toast ( plugin required https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lastTimeBackPress=0; | |
var timePeriodToExit=2000; | |
function onBackKeyDown(e){ | |
e.preventDefault(); | |
e.stopPropagation(); | |
if(new Date().getTime() - lastTimeBackPress < timePeriodToExit){ | |
navigator.app.exitApp(); | |
}else{ | |
window.plugins.toast.showWithOptions( | |
{ | |
message: "Press again to exit.", | |
duration: "short", // which is 2000 ms. "long" is 4000. Or specify the nr of ms yourself. | |
position: "bottom", | |
addPixelsY: -40 // added a negative value to move it up a bit (default 0) | |
} | |
); | |
lastTimeBackPress=new Date().getTime(); | |
} | |
}; | |
document.addEventListener("backbutton", onBackKeyDown, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment