Portal_Zii Portal_Zii - 1 year ago 171
Javascript Question

Can Javascript know if a user has selected the box that disables alerts (Prevent page from creating additional dialogues)

I have a delete button and on

it creates an alert pop-up which lets the user confirm or cancel deleting that object.

Here is my js for that:

.mouseover(function() { $(this).closest('li').css("opacity", "0.7");
}).mouseout(function() { $(this).closest('li').css({ "opacity": "1", "background-color": "#89b8d7" });
}).mousedown(function() { $(this).closest('li').css("background-color", "#b71124");
}).mouseup(function() {
var txt;
var r = confirm("Are you sure you want to delete this file?");
if (r == true) {
$(this).closest('li').css("display", "none");
} else {
$(this).closest('li').css("display", "inline-block;");


If the user selects (prevent this page from creating additional dialog boxes) option - it completely disables the delete function.

How do I alter my current code to create a fallback for when the user disables the pop up boxes. For example: How would I write the code so that if the user disables the popup alert to confirm deleting the object then the object will just be deleted anyways without any additional warnings.



I guess my real question is IS it possible in javascript to know if the user checked the box disabling the alert and in so create a function based off that information.

So i am not trying to prevent users from disabling the popup. But my popup enables the delete function for my object. So I simply wana add a bit of javascript that knows if the user disabled the alert and if so then the deleted button just deletes the object anyways without any popup safety net asking if the user is sure they wana delete it. I actually like that the user can disable the alert in-case they find it annoying.

Answer Source

EDIT converted to wiki because duplicate to how to know whether modal boxes (alert, prompt, confirm…) have been disabled in javascript?

What you could do is to measure the time the dialog was visible.

If it is was only visible less then some milliseconds then it most likely was not shown at all, or the user closed it immediately:

function customConfirm( msg ) {
  var startTime = new Date();
  var result = confirm(msg);
  var stopTime = new Date();

  if( stopTime.getTime() - startTime.getTime() < 100 ) {
     //do some fallback 
     //and call callback depending on how you implemented the fallback
  } else {

customConfirm('Are you sure you want to delete this file?', function(r) {
  if (r == true) {
    $(this).closest('li').css("display", "none");
  } else {
    $(this).closest('li').css("display", "inline-block;");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download