如何知道模态框(警报、提示、确认...)是否已在 javascript 中被禁用?

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

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

问题描述

我有一个基于网络的私人应用程序,有时我会真诚地询问用户在特定情况下他们想做什么.为此,我使用了 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/

我稍微查看了 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 中被禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何知道模态框(警报、提示、确认...)是否已在 javascript 中被禁用?

基础教程推荐