确认对话框返回false立即 [英] confirm dialog returns false immediately

查看:149
本文介绍了确认对话框返回false立即的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code:

index.html:
    ...
      <script type="text/javascript" charset="utf-8" src="main.js"></script>
    </head>
    <body onload="init();"></body>
    ...

main.js:
    function onBackPressed(e) {
        console.log("onBackPressed()");
        var answer = confirm("Do you want to exit?");
        console.log(answer);
        if (answer) {
            navigator.app.exitApp();
        }
    }
    function init() {
        ...
        document.addEventListener("backbutton", onBackPressed, false);
        ...
    }

当我退出应用程序第一次,一切似乎是确定。
问题是,当我下一次启动应用程序时,确认对话框虚假立即对话框保持可见返回。所以,当我点击OK什么都不会发生。

When I exit application first time, everything seems to be ok. The problem is when I start application next time, confirmation dialog returns false immediately and dialog stay visible. So when I click "OK" nothing will happen.

下面是logcat的输出:

Here is output from logcat:

04-11 16:16:26.444: D/PhoneGapLog(18356): onBackPressed()
04-11 16:16:26.444: D/PhoneGapLog(18356): file:///android_asset/www/main.js: Line 49 : onBackPressed()
04-11 16:16:26.444: I/Web Console(18356): onBackPressed() at file:///android_asset/www/main.js:49
04-11 16:16:26.584: D/PhoneGapLog(18356): false
04-11 16:16:26.584: D/PhoneGapLog(18356): file:///android_asset/www/main.js: Line 51 : false
04-11 16:16:26.584: I/Web Console(18356): false at file:///android_asset/www/main.js:51

这是在PhoneGap的还是Android的错误?或者说我做错了什么?

Is this a bug in phonegap or android? Or I'm doing something wrong?

我使用的Nexus One采用Android 2.3.6和1.4.1的PhoneGap(1.5版本有后退按钮事件的问题)。

I use Nexus One with android 2.3.6 and phonegap 1.4.1 (version 1.5 have issue with backbutton event).

推荐答案

在PhoneGap的,确认是做一个异步回调。请参阅<一个href=\"http://docs.phonegap.com/en/1.5.0/phonegap_notification_notification.md.html#notification.confirm\"相对=nofollow> API文档。

In PhoneGap, confirm is does an asynchronous callback. See the api docs.

变量的答案的永远是因为立即返回假的。

The variable answer will always be false because of the immediate return.

在code应该看起来更像是:

The code should look more like:

    // process the confirmation dialog result
function onConfirm(button) {
    alert('You selected button ' + button);
}

// Show a custom confirmation dialog
//
function showConfirm() {
    navigator.notification.confirm(
        'You are the winner!',  // message
        onConfirm,              // callback to invoke with index of button pressed
        'Game Over',            // title
        'Restart,Exit'          // buttonLabels
    );
}

这篇关于确认对话框返回false立即的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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