如何检测“防止该页面创建额外的对话框” [英] How to Detect "prevent this page from creating additional dialogs"

查看:166
本文介绍了如何检测“防止该页面创建额外的对话框”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何检测用户是否勾选了阻止此页面创建其他对话框? b $ b

为什么这是一个问题

如果用户阻止了确认框的出现,函数确认('foobar') 总是返回false。


$ b

上下文



所以,我使用的代码如 if(confirm('you sure?')){// stuff ...} 。因此,浏览器自动回复 false 会阻止用户执行 stuff 。但是,如果有方法检测到用户已经检查了该框,那么我可以自动执行该操作。

我认为如果用户禁用了对话,那么函数应该抛出一个错误,或者返回true。该功能是为了确认用户请求的操作。

解决方案

据我所知,这是不可能的做任何干净的方式,因为它是一个浏览器功能,如果浏览器不让你知道,那么你不知道。



然而,你可以做的是写一个包装确认()的时间的响应时间。如果它太快而不能成为人类,那么提示很可能被压制,而不是虚假的。你可以通过多次运行confirm()来使其更稳健,只要它返回false,所以它是一个超快用户的概率是非常低的。



包装将是这样的:

pre $函数myConfirm(消息){
var start = new Date()。getTime ();
var result = confirm(message);
var dt = new Date()。getTime() - start;
// dt< 50ms意味着可能的计算机
//最快的时候我可以得到期望的弹出是100ms
//最慢我从计算机抑制得到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;
返回结果; PS:如果你想要一个实用的解决方案,而不是这个黑客,耶日Zawadzki的建议使用库做确认对话框可能是最好的方法。


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 user has prevented the appearance of confirm boxes, the function confirm('foobar') always returns false.

If the user cannot see my confirmation dialogue boxes confirm('Are you sure?'), then the user can never perform the action.

CONTEXT

So, I use the code like if(confirm('are you sure?')){ //stuff... }. So an auto-response of false from the browser will prevent the user from ever doing stuff. But, if there was a way to detect that the user has checked the box, then I could execute the action automatically.

I think that if the user has disabled the dialogues, then the function should either throw an error, or return true. The function is meant to confirm an action that the user has requested.

解决方案

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.

这篇关于如何检测“防止该页面创建额外的对话框”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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