试试这个:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false); //Listen to the User clicking on the back button
}
function onBackKeyDown(e) {
e.preventDefault();
navigator.notification.confirm("Are you sure you want to exit ?", onConfirm, "Confirmation", "Yes,No");
// Prompt the user with the choice
}
function onConfirm(button) {
if(button==2){//If User selected No, then we just do nothing
return;
}else{
navigator.app.exitApp();// Otherwise we quit the app.
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
当第一次单击设置exitApp = true时,第二次单击后退按钮将退出应用程序.但是设置一个Interval将exitApp的状态更改为false.因此,当在1秒内点击两次按钮时,将退出应用程序.
document.addEventListener('deviceready', function() {
var exitApp = false, intval = setInterval(function (){exitApp = false;}, 1000);
document.addEventListener("backbutton", function (e){
e.preventDefault();
if (exitApp) {
clearInterval(intval)
(navigator.app && navigator.app.exitApp()) || (device && device.exitApp())
}
else {
exitApp = true
history.back(1);
}
}, false);
}, false);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21854 次 |
| 最近记录: |