简体   繁体   中英

Override javascript confirm box

I am trying to override javascript confirm box with SweetAlert . I have researched also about this but I can't found proper solution.

I am using confirm like this

if (confirm('Do you want to remove this assessment') == true) {
   //something
}
else {
   //something
}

And I am using this for overriding

 window.confirm = function (data, title, okAction) {
                swal({
                    title: "", text: data, type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes", cancelButtonText: "No", closeOnConfirm: true, closeOnCancel: true
                }, function (isConfirm) {
                    if (isConfirm)
                    {
                        okAction();
                    }
                });
                // return proxied.apply(this, arguments);
            };

Now confirm box is replaced with sweetalert. When user click on Yes button then OK action of confirm box should be called. But this isn't calling

And In above code an error occurred Uncaught TypeError: okAction is not a function .

Please suggest me I should I do for override confirm box.

Since the custom implementation is not a blocking call, you need to call it like

confirm('Do you want to remove this assessment', function (result) {
    if (result) {
        //something
    } else {
        //something
    }
})


window.confirm = function (data, title, callback) {
    if (typeof title == 'function') {
        callback = title;
        title = '';
    }
    swal({
        title: title,
        text: data,
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes",
        cancelButtonText: "No",
        closeOnConfirm: true,
        closeOnCancel: true
    }, function (isConfirm) {
        callback(isConfirm);
    });
    // return proxied.apply(this, arguments);
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM