how to know whether modal boxes (alert, prompt, confirm…) have been disabled in javascript?

When that box is checked, the dialog “closes” immediately. You could check to see if the box closes unusually fast:

function dialog(message, success, failure) {
    var open_time = new Date();
    var result = alert(message);
    var close_time = new Date();

    if (close_time - open_time < 10) {
        failure();
    } else {
        success(result);
    }
}

dialog('Hello', function(result) {
    // The dialog probably was closed by the user
}, function() {
    // The dialog was closed really fast.
    // Either the user was typing while it popped up or the browser didn't
    //  display it in the first place
});

Although just using CSS and HTML to create modal dialogs would probably be much easier and more consistent across browsers and platforms. I personally don’t like Chrome’s approach.

Demo: http://jsfiddle.net/tS9G6/4/

I looked a little bit through Chromium’s source and that property isn’t stored anywhere, so there doesn’t seem to be some Chromium-specific property that you can look at.

Leave a Comment