简体   繁体   English

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

[英]how to know whether modal boxes (alert, prompt, confirm…) have been disabled in javascript?

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. 为此,我正在使用javascript的confirm功能。

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: 与任何其他模式框一样,在几次弹出窗口之后,用户可以选择通过单击如下所示的小框来禁用它们:

在此输入图像描述

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! 问题是,如果他们点击一次,他们永远不会看到其他消息和confirm响应假定为0 ,这是令人困惑的,因为基本上它意味着所有需要确认的操作都会被取消而不会发出警告! 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
});

Although just using CSS and HTML to create modal dialogs would probably be much easier and more consistent across browsers and platforms. 虽然只是使用CSS和HTML来创建模态对话框,但在浏览器和平台之间可能会更容易和更一致。 I personally don't like Chrome's approach. 我个人不喜欢Chrome的方法。

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

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. 我看了一下Chromium的来源,并且该属性没有存储在任何地方,因此似乎没有一些特定于Chromium的属性可供您查看。

You can't do anything about it. 你无能为力。 It's a browser feature. 这是一个浏览器功能。

You can check for the timing - 你可以检查时间 -

How to Detect "prevent this page from creating additional dialogs" 如何检测“阻止此页面创建其他对话框”

This suggests doing the following : 这表明做了以下事情:

function myConfirm(message){
    var start = new Date().getTime();
    var result = confirm(message);
    var dt = new Date().getTime() - start;
    // dt < 50ms means probable computer
    // the quickest I could get while expecting the popup was 100ms
    // slowest I got from computer suppression was 20ms
    for(var i=0; i < 10 && !result && dt < 50; i++){
        start = new Date().getTime();
        result = confirm(message);
        dt = new Date().getTime() - start;
    }
    if(dt < 50)
       return true;
    return result;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用警报/确认/提示模式实现使用模式挂钩? - How to implement a use-modal-hook with a alert/confirm/prompt pattern? Javascript 弹出框(警报、确认和提示)是“文档”的一部分还是“浏览器”(客户端)的一部分 - Are Javascript popup boxes (Alert, confirm and prompt) part of 'document' or part of 'Browser' (Client) 如何将即时警报和确认放在一起? - How to put prompt alert and confirm together? 当网站安装为PWA时,如何在Microsoft Edge中启用javascript警报和确认框? - How to enable javascript alert and confirm boxes in Microsoft Edge when a website installed as PWA? 如何知道是否已使用javascript加载了图像 - how to know whether or not a image has been loaded using javascript 为什么JavaScript对话框(警告,确认)停止重新绘制页面? - Why does JavaScript dialog boxes (alert, confirm) stop page redrawing? 提示,警告并确认未找到Android WebView中的JavaScript - Prompt, Alert and confirm JavaScript inside a Android WebView not found WKWebView JavaScript警报,提示,确认将不起作用 - WKWebView javascript alert, prompt, confirm won't work 不出现警告和确认框 - alert and confirm boxes do not appear 覆盖默认警报和确认框 - Overriding default alert and confirm boxes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM