用户在Javascript中触摸空白屏幕时关闭警报框

Mal*_*jun 5 javascript jquery android cordova

我有一个简单的问题,我试图在谷歌找到解决方案,但没有得到任何解决方案,因为搜索关键字,我想是这样.我通过javascript显示警告框,但当用户触摸空白(警报窗口外)屏幕时它会自动关闭我的意思是没有用户交互也关闭它.它还没有关闭Android 2.2版本.它只关闭更高版本.可能是什么问题?请问有人遇到这个问题吗?

下面的代码是小图像的触摸事件.警告框在屏幕中心提示但是当用户在警告框窗口外触摸时关闭

$('#bombImg').on('touchstart',function(touchEvent) {
        sound = new Media("/android_asset/www/beep2.mp3");
        sound.play();
        document.getElementById('resetBtn').disabled = false;
        document.getElementById('trns').style.display = "none";
        document.getElementById('bombImg').style.display = "none";
        document.getElementById('cityImg').style.position = 'absolute';
        document.getElementById('bomb').style.display = "block";
        enableZoomButtons();
        window.alert("Bomb defused");
        touchEvent.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

这是我的Java代码

 public class Adventure extends DroidGap {
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setIntegerProperty("splashscreen", R.drawable.logo);
    // super.setIntegerProperty("splashscreen", R.drawable.splash);
    //super.setStringProperty("loadingDialog", "Loading..");
    super.loadUrl("file:///android_asset/www/index.html", 10000);
    this.setFinishOnTouchOutside(false);
    super.appView.addJavascriptInterface(new JavaScriptInterface(this,
            appView, this), "MyAndroid");
    appView.setOnClickListener(null);
    WebSettings settings = appView.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setSupportZoom(true);
    settings.setDefaultZoom(ZoomDensity.MEDIUM);
    appView.getSettings().setUseWideViewPort(false);
    appView.getSettings().setJavaScriptEnabled(true);
    // appView.loadUrl("javascript:getValue()");
}    
}      
Run Code Online (Sandbox Code Playgroud)

请有人回答这个问题

And*_*i B 0

Chrome使用默认的Android Dialog来显示与alert、prompt、confirm方法对应的UI。

Dialog 类有一个名为 setCanceledOnTouchOutside 的方法来管理标志。当该标志为 true 时,点击对话框外部意味着用户取消对话框(类似于在桌面浏览器中按 ESC)。

在旧版本的 Android 中,该标志默认为 false。在较新的版本中(根据此http://tofu0913.blogspot.ro/2012/09/android-dialog-setcanceledontouchoutside.html的 ICS+ ),该标志默认为 true。

如果您想获得您尝试过的内容,您可以使用覆盖层和一些模拟警报的 HTML。

对于想要进一步测试的人:http://jsfiddle.net/s7TWH/(我用 2.3 - 标志为 false 和 4.4 - 标志为 true 进行了测试):

$('#bombImg').on('touchstart',function(touchEvent) {
    window.alert("Bomb defused");
    touchEvent.preventDefault();    
});
Run Code Online (Sandbox Code Playgroud)