首页 > 解决方案 > 检查警报是否被阻止

问题描述

目前,我有:

if (confirm("Are you sure?")) { do something }

是否可以检查用户是否选中了“防止此页面创建其他对话框”框?

我想做的是:

var dialogsPrevented = // boolean that depicts whether dialogs are being suppressed.
if (dialogsPrevented || confirm("Are you sure?")) { do something }

标签: javascript

解决方案


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.


推荐阅读