科尔多瓦后卫事件没有解雇

时间:2016-06-29 05:37:48

标签: javascript android cordova

我正在尝试按照 Here的说明收听Android设备上的后退按钮。下面是我的代码

var app = {
     initialize: function() {
        this.bindEvents();
    },
 bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
        document.addEventListener('resume', this.onDeviceResume, false);
    },
   onDeviceReady: function() {
        document.addEventListener('backbutton', this.onBackKeyDown, false);
        app.receivedEvent('root');
        codePush.sync();
    },

onBackKeyDown: function (e) {
        if (window.location.pathname === '/') {
             navigator.notification.confirm(
                'You are the winner!',  // message
                onConfirm,              // callback to invoke with index of button pressed
                'Game Over',            // title
                'Restart,Exit'          // buttonLabels
            );
            e.preventDefault();
            navigator.app.exitApp();
        } else {
            navigator.app.backHistory();
        }
    }

}

app.initialize();

我的活动似乎没有点击后退按钮。我甚至添加了一个退出测试但没有任何变化。

onBackKeyDown: function (e) {
   navigator.app.exitApp();
}

请问我该怎么做?有什么我做错了吗?任何帮助将不胜感激。

我的home.html下面

<body>

<div id="root" class="root app">
    <div class="mobile-page">
        <img class="spinner" src="img/my-symbol-logo.svg" />
        <p class="event listening">Connecting to Device</p>
        <p class="event received">Device is Ready</p>
    </div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="index.js"></script>

更新

内容安全政策。

<meta http-equiv="Content-Security-Policy" content="default-src * 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">

0 个答案:

没有答案
相关问题