最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Check if alert is disabled - Stack Overflow

programmeradmin2浏览0评论

In chrome there is a way to disable alerts by selecting "prevent this page from creating additional dialogs".

Is there a way to check via javascript if the user has disabled the alerts ?

In chrome there is a way to disable alerts by selecting "prevent this page from creating additional dialogs".

Is there a way to check via javascript if the user has disabled the alerts ?

Share Improve this question asked Mar 2, 2016 at 8:06 xRobotxRobot 26.6k72 gold badges192 silver badges317 bronze badges 2
  • 1 See this answer: stackoverflow./questions/20672490/… – Anoxy Commented Mar 2, 2016 at 8:12
  • As far as I know, this is not possible to do in any clean way as it's a browser feature, and if the browser doesn't let you know then you can't know. – RRR Commented Mar 2, 2016 at 8:14
Add a ment  | 

1 Answer 1

Reset to default 11

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. Also, there is very unlikely that someone will be able to process a working-alert within 50 milliseconds.

发布评论

评论列表(0)

  1. 暂无评论