Home  >  Q&A  >  body text

javascript how to know if the browser has disabled confirm

When calling the browser's confirm, a confirmation box pops up and then you choose to disable it. When the code calls the confirm method again, it will still return false. Can js know that the browser's confirm has been disabled.

世界只因有你世界只因有你2615 days ago921

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-05-19 10:45:16

    没有想到优美的解决方案。

    有个讨巧的方式:如果用户选择了禁用,那么在调用这个方法的时候,不会阻塞代码,会立刻执行下段代码。我们可以设置个计时器,时间在毫秒级结束,就说明客户端阻止了弹窗。

    var begin = Date.now();
    
    //如果客户端没有禁用confirm,那么这个弹窗会阻塞代码继续往下执行,直到用户点了确认或取消,
    // 那么end与start之间的值就会比较大了。
    //反之,end与start之间的值就非常小了,毫秒级。
    var result = window.confirm('hello'); 
    
    var end = Date.now();
    if (end - begin < 10) {
        console.log('用户禁用了confirm弹窗');
    }

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-19 10:45:16

    无法知道。

    建议用自己编写对话框代替。

    Never Use a Warning When you Mean Undo

    reply
    0
  • Cancelreply