【问题标题】:On using double tap on back button to exit app jquery code in cordova and touching on the screen, the app exits在使用双击后退按钮退出科尔多瓦中的应用程序 jquery 代码并触摸屏幕时,应用程序退出
【发布时间】:2019-06-20 12:34:41
【问题描述】:

我正在尝试为 Android 创建一个 Cordova 应用程序。在我的应用程序中,我需要功能,在单击我的 Cordova 应用程序的默认后退按钮时,它会显示一个通知/对话框/消息,上面写着“再次按以退出应用程序”。单击“是”时,它应该退出应用程序。单击“否”后,它应该保留在应用程序中。在消息框外点击它会退出应用程序,但在消息框外点击它应该留在应用程序内。我在我的应用程序中使用了 cordova 对话框插件。

预期结果:在消息框外点击时,它应该留在应用内。

实际结果:在消息框外点击会退出应用程序。

谁能帮我解决这个问题?提前谢谢..!

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
  document.addEventListener("backbutton", function(e) {
    e.preventDefault();
    navigator.notification.confirm("Press again to exit from the app", onConfirmExit, "", "Yes,No");
  }, false);
}

function onConfirmExit(button) {
  if (button == 2) {
    return;
  } else {
    navigator.app.exitApp();
  }
}

【问题讨论】:

    标签: javascript android jquery cordova cordova-plugins


    【解决方案1】:

    我从您的代码中编辑了几行

    document.addEventListener("deviceready", onDeviceReady, false);
    
    function onDeviceReady() {
      document.addEventListener("backbutton", function(e) {
        e.preventDefault();
        navigator.notification.confirm("Press again to exit from the app", onConfirmExit, "Yes", "No");
      }, false);
    }
    
    function onConfirmExit(button) {
      if (button == 1) {
        navigator.app.exitApp();
      } else {
        
      }
    }

    您已在一个文件中添加了是和否。它们应该在单独的参数中。

    Yes 索引号为 1,No 为 2。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-08
      • 2015-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多