How to Detect “prevent this page from creating additional dialogs”

后端 未结 2 1553
一向
一向 2020-12-10 11:35

QUESTION

How can I detect if a user has checked the box, "prevent this page from creating additional dialogs"?

WHY It\'s a problem

If the

相关标签:
2条回答
  • 2020-12-10 12:21

    As far as I know, this is not possible to do in any clean way as it's a browser feature, and if the browser doesn't let you know then you can't know.

    However, what you could do is write a wrapper around confirm() that times the response time. If it is too fast to be human then the prompt was very probably suppressed and it would return true instead of false. You could make it more robust by running confirm() several times as long as it returns false so the probability of it being an über-fast user is very low.

    The wrapper would be something like this:

    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;
    }
    

    PS: if you want a practical solution and not this hack, Jerzy Zawadzki's suggestion of using a library to do confirmation dialogs is probably the best way to go.

    0 讨论(0)
  • 2020-12-10 12:28

    I think you cannot change it - it's browser feature.

    My first idea if you need workaround would be to change code from using system confirm to some js library alert (from e.g. jQuery UI)

    0 讨论(0)
提交回复
热议问题