javascript - 检查警报是否被阻止
问题描述
目前,我有:
if (confirm("Are you sure?")) { do something }
当消息显示并且用户单击“确定”时,它是
true
.当消息显示并且用户单击“取消”时,它是
false
.如果用户选中“阻止此页面创建其他对话框”框,则确认将始终返回
false
。
是否可以检查用户是否选中了“防止此页面创建其他对话框”框?
我想做的是:
var dialogsPrevented = // boolean that depicts whether dialogs are being suppressed.
if (dialogsPrevented || confirm("Are you sure?")) { do something }
解决方案
Check Date.now()
before and after. Unless the user clicked the button within like a hundredth of a second, you can be fairly sure the dialog was blocked.
function checkedConfirm(query) {
var time = Date.now();
var response = confirm(query);
if( response) return "TRUE";
if( Date.now() - time > 10) return "FALSE";
return "DIALOG_NOT_FOUND";
}
Adjust return values as necessary/useful.
推荐阅读
- list - 如何使用 foldr 在列表中相互添加变量?
- javascript - 获取 span 标签内的值并根据条件更改背景颜色?
- python - 创建比较数据框的三向维恩图的最佳方法?
- c# - c#不能隐式转换类型
- python-3.x - 平方多维数组,包括交叉项,没有 for 循环
- python - Django 过滤器错误子选择返回 2 列 - 预期为 1
- javascript - 重复 Javascript 幻灯片
- python - Django 将方括号和引号添加到 charfield 输入
- windows - Makefile 未读取时间戳变量
- swift - 为 UIButton 添加左右填充