jquery - 关闭 Android 应用 Jquery - Phonegap

标签 jquery android cordova

我正在尝试使用以下代码关闭我的 Phonegap Android 应用程序:

document.addEventListener("backbutton", function () { 
    if ($('.screenshot').is(":visible")) {
        if (confirm('Afsluiten?')){
            setTimeout( function() { navigator.app.exitApp(); });
        }
        else {
            '';
        }
    }
    else {
        $(".items , .screenshot").show();
        $(".content , .openbrowser , .html5vid , .introtekst_gal" ).hide();
        $(".terug").hide();
    }
}, true);

它只工作一次:按后退按钮然后按“确定”关闭应用程序,如预期的那样。

但是当我这样做时,应用程序不再关闭:

  • 按后退按钮(弹出显示)
  • 按“取消”(弹出窗口消失)
  • 按后退按钮(弹出显示)
  • 按“确定”(弹出窗口消失,应用应该关闭,但没有关闭)

我做错了什么?

最佳答案

你可以试试这个代码:

     document.addEventListener("backbutton", function () { 
         navigator.notification.confirm(
             'Do you want to quit', 
             onConfirmQuit, 
             'QUIT TITLE', 
             'OK,Cancel'  
         );
     }, true); 


    function onConfirmQuit(button){
        if(button == "1"){
            navigator.app.exitApp(); 
        }
    }

关于jquery - 关闭 Android 应用 Jquery - Phonegap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10123005/

相关文章:

android - 找不到 phonegap 推送插件类

android - Phonegap- 支持推送通知

javascript - 仅当特定按钮类型导致表单提交时,如何为表单提交添加选择器

javascript - Img 加载和嵌套 div

jQuery 页面改进

javascript - 我可以根据点击功能找到输入元素吗

java - Gradle 项目同步失败。基本功能 - 在 Android Studio 2.2 上失败

android - 类型错误 : Cannot read property 'getPictures' of undefined

android 在不同的设备中通信两个应用程序

java - 使用按钮打开谷歌地图到当前位置