xRobot
xRobot

Reputation: 26567

Check if alert is disabled

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 ?

Upvotes: 11

Views: 1134

Answers (1)

gurvinder372
gurvinder372

Reputation: 68393

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.

Upvotes: 11

Related Questions