fabien-d / alertify.js

JavaScript Alert/Notification System
http://fabien-d.github.com/alertify.js/
4.26k stars 726 forks source link

Confirm not working... :::sigh::: #242

Open hoteloptics opened 9 years ago

hoteloptics commented 9 years ago

I'm creating HTML within a PERL wrapper, and I have an href link that is giving me fits.

<a href="sumperlcode.cgi?a=test&b=me" id="confirm">This-Is-My-Link</a>

The code that's being invoked is:

$("#confirm").on('click', function(event) {
reset();
var loc = $(this).attr('href');
alertify.confirm("WARNING:  This operation cannot be undone!", function (e) {
if (e) {
    document.location.href = loc;
}
});
});

I've also tried the following, which also didn't work:

    $("#confirm").on( 'click', function () {
        reset();
        alertify.confirm("This is a confirm dialog", function (e) {
            if (e) {
                alertify.success("You've clicked OK");
            } else {
                alertify.error("You've clicked Cancel");
            }
        });
        return false;
    });

Browser=Firefox

The behavior that's happening is that the confirmation dialog stays open for about 1 split second, then disappears, and the default action fires off.

Any idea what I'm doing wrong?

christrain91 commented 8 years ago

Use event.preventDefault()

luissalamank commented 8 years ago

I have the same problem, I tried event.preventDefault(); but doesn't work for me.

DeWetdeJager commented 8 years ago

Try this

$("#confirm").on( 'click', function (e) { if(e.preventDefault){e.preventDefault();} reset(); alertify.confirm("This is a confirm dialog", function (e) { if (e) { alertify.success("You've clicked OK"); } else { alertify.error("You've clicked Cancel"); } }); });