javascript how to know if the browser has disabled confirm
世界只因有你2017-05-19 10:43:16
0
2
999
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.
There is a trick: if the user chooses to disable it, then when calling this method, the code will not be blocked and the next code will be executed immediately. We can set a timer. When the time expires at the millisecond level, it means that the client has blocked the pop-up window.
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弹窗');
}
No elegant solution came to mind.
There is a trick: if the user chooses to disable it, then when calling this method, the code will not be blocked and the next code will be executed immediately. We can set a timer. When the time expires at the millisecond level, it means that the client has blocked the pop-up window.
No way of knowing.
It is recommended to write your own dialog box instead.
Never Use a Warning When you Mean Undo