Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if alert is disabled

Tags:

javascript

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 ?

like image 445
xRobot Avatar asked Mar 02 '16 08:03

xRobot


1 Answers

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.

like image 163
gurvinder372 Avatar answered Oct 17 '22 22:10

gurvinder372