简体   繁体   English

检查警报是否已禁用

[英]Check if alert is disabled

In chrome there is a way to disable alerts by selecting "prevent this page from creating additional dialogs". 在chrome中,有一种方法可以通过选择“阻止此页面创建其他对话框”来禁用警报。

Is there a way to check via javascript if the user has disabled the alerts ? 如果用户已禁用警报,有没有办法通过javascript检查?

try this demo 试试这个演示

function checkIfAlertDisabled()
{
   var startTime = new Date().getTime();
   alert("asdasdasdasdasdasd");
   var endTime = new Date().getTime();

   return ( endTime - startTime ) < 50; 
}

console.log( checkIfAlertDisabled() );

I think 50 is a safe number since usually it won't take more than 1 millisecond to process a non-working alert. 我认为50是一个安全数字,因为处理非工作警报通常不会超过1毫秒。 Also, there is very unlikely that someone will be able to process a working-alert within 50 milliseconds. 此外,有人不可能在50毫秒内处理工作警报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM