如何知道模态框(警告,提示,确认...)是否已在javascript中禁用? [英] how to know whether modal boxes (alert, prompt, confirm...) have been disabled in javascript?

查看:119
本文介绍了如何知道模态框(警告,提示,确认...)是否已在javascript中禁用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于Web的私人应用程序,有时我确实会问用户在给定情况下想要做什么.为此,我正在使用javascript的confirm函数.

I have a private web based app where sometimes I genuinely ask to the users what they want to do in given situations. To do so, I'm using the confirm function of javascript.

与其他任何模式框一样,在弹出几个窗口之后,用户可以选择禁用它们,只需单击如下所示的小框即可:

As any other modal box, after a few popups the user has the choice to disable them by simply clicking the little box as showed below:

问题是,如果单击一次,他们将永远看不到其他消息,并且对confirm的响应被假定为0,这令人困惑,因为从根本上讲,这意味着所有需要确认的操作都被取消了,而没有警告. !刷新页面无济于事,他们必须将其关闭然后重新打开才能再次使用.

The problem is that, if they clicked it once, they never see other messages and responses to confirm are assumed 0, which is confusing because basically it means that all the actions requiring their confirmation are cancelled with no warning! Refreshing the page does not help, they have to close it and reopen it for it to work again.

我可以检测到他们何时选中了那个小盒子吗?

Can I detect when they checked that little box?

推荐答案

选中该框后,对话框立即关闭".您可以检查一下该框是否关闭异常快:

When that box is checked, the dialog "closes" immediately. You could check to see if the box closes unusually fast:

function dialog(message, success, failure) {
    var open_time = new Date();
    var result = alert(message);
    var close_time = new Date();

    if (close_time - open_time < 10) {
        failure();
    } else {
        success(result);
    }
}

dialog('Hello', function(result) {
    // The dialog probably was closed by the user
}, function() {
    // The dialog was closed really fast.
    // Either the user was typing while it popped up or the browser didn't
    //  display it in the first place
});

尽管仅使用CSS和HTML创建模式对话框可能会在浏览器和平台之间更加容易且更加一致.我个人不喜欢Chrome的方法.

Although just using CSS and HTML to create modal dialogs would probably be much easier and more consistent across browsers and platforms. I personally don't like Chrome's approach.

演示: http://jsfiddle.net/tS9G6/4/

Demo: http://jsfiddle.net/tS9G6/4/

我从Chromium的源头看了一下,该属性没有存储在任何地方,因此似乎没有一些Chromium特定的属性可供您查看.

I looked a little bit through Chromium's source and that property isn't stored anywhere, so there doesn't seem to be some Chromium-specific property that you can look at.

这篇关于如何知道模态框(警告,提示,确认...)是否已在javascript中禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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