在离子应用程序禁用硬件后退按钮? [英] Disable hardware back button in Ionic application?

查看:167
本文介绍了在离子应用程序禁用硬件后退按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图禁用我的科尔多瓦应用程序中的后退按钮。
我使用AngularJS +离子框架。
我发现这个主题,并试图在code波纹管,但是它绝对没有任何影响。任何想法?
谢谢!

I'm trying to disable the back button on my Cordova app. I'm using AngularJS + Ionic Framework. I found topics about this and tried the code bellow, but it has absolutely no effect. Any idea? Thanks!

index.html的

index.html

<head>
    <script>
      document.addEventListener("deviceready", onDeviceReady, false);
        function onDeviceReady() {
            document.addEventListener("backbutton", function (e) {
                e.preventDefault();
                console.log("hello");
            }, false );
        }
    </script>
</head>

请注意,当我按下后退按钮,我有你好显示在我的控制台。

Note that when I push back button, I have "hello" displayed in my console.

推荐答案

终于找到了对离子论坛线程答案:

Finally found the answer on Ionic Forum thread:

<一个href=\"http://forum.ionicframework.com/t/handling-the-hardware-back-buttons/1505/7\">http://forum.ionicframework.com/t/handling-the-hardware-back-buttons/1505/7

$ionicPlatform.registerBackButtonAction(function () {
  if (condition) {
    navigator.app.exitApp();
  } else {
    handle back action!
  }
}, 100);

$ ionicPlatform.registerBackButtonAction允许完全地覆盖后退按钮行为。
第一个参数是一个回调函数和secondone优先级(仅具有最高优先级被执行回调)。

$ionicPlatform.registerBackButtonAction allows to completly overwrite back button behavior. First param is a callback function and the secondone a priority (only the callback with the highest priority gets executed).

这篇关于在离子应用程序禁用硬件后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆